kyamagu / matlab-json

Use official API: https://mathworks.com/help/matlab/json-format.html
Other
52 stars 15 forks source link

Fields out of order #6

Closed zakimohzani closed 8 years ago

zakimohzani commented 8 years ago

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.

kyamagu commented 8 years ago

@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.

zakimohzani commented 8 years ago

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 https://github.com/kyamagu/matlab-json/issues/6#issuecomment-200723216