kyamagu / matlab-json

Use official API: https://mathworks.com/help/matlab/json-format.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fields out of order

zakimohzani opened this issue · comments

Hello Mr. Yamaguchi,

Just for the benefit of other users, I've found another bug while testing simple stuff on json0.2.2:

json.write fails to preserve field order. Example:

a.a = 1;
a.b = 2;
a.c = 3;

>> json.write(a, 'test.json', 'indent', 1)


Result is:

{
 "b": 2,
 "c": 3,
 "a": 1
}

And that's the order I get when using json.read

On the other hand, the JSONLab library on MathWorks handles this properly.

Thanks for your efforts. You don't need to solve this.

@zakimohzani JSON object has unordered fields according to the JSON specification. If your code rely on the order of JSON fields, you should stop doing so.

Ah ok, thanks for that. I mentioned it because a + b for Matlab requires
that both a n b structs to have their fields in the same order for
performance reasons. If this is the case for JSON, then I'll include the
order in another field :)
Am 24.03.2016 4:03 Nachm. schrieb "Kota Yamaguchi" <notifications@github.com

:

@zakimohzani https://github.com/zakimohzani JSON object has unordered
fields according to the JSON specification http://json.org. If your
code rely on the order of JSON fields, you should stop doing so.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#6 (comment)