struct2json

struct2json(s) converts the struct object s into a json string.

Examples

>> s = struct('country', 'Spain', 'capital', 'Madrid', 'population', '3,141,991')
j = struct2json(s)#

{"country":"Spain","capital":"Madrid","population":"3,141,991"}
>> s1 = struct('name', 'Ford', 'years', 4)
s2 = struct('name', 'Nissan', 'years', 10)
s = struct('name', 'John', 'age', 30, 'cars', {s1,s2})
j = struct2json(s)#

{"name":"John","age":30,"cars":[{"name":"Ford","years":4}, {"name":"Nissan","years":10}]}

See also

json | struct