Why does the ordering of JSON object field names matter in the "jsondecode" function?
Show older comments
I am using MATLAB to read JSON-formatted text using the "jsondecode" function.
For JSON-formatted text containing objects with the same field names in the same order, the "jsondecode" function will return a structure array:
>> jsondecode('[{"a": 1, "b": 2}, {"a": 3, "b": 4}]')
ans =
2×1 struct array with fields:
a
b
However, if the same field names are in a different order, the "jsondecode" function will return a cell array of scalar structures:
>> jsondecode('[{"a": 1, "b": 2}, {"b": 3, "a": 4}]')
ans =
2×1 cell array
{1×1 struct}
{1×1 struct}
What is the reason for this behavior difference and how can I work around this?
Accepted Answer
More Answers (0)
Categories
Find more on JSON Format in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!