jsonencode not encoding entire large structure data
23 views (last 30 days)
Show older comments
Hi
I have a large table converting to structure type and then use the jsonencode to encode the data.
However I realized that not all data has been converted to json, since the ending was not "]" or "}".
Is there a fail-safe way to convert large table to json?
Thanks,
1 Comment
Rik
on 23 Mar 2024
Can you attach the data you are trying to convert? Or can you generate a variable with fake/random data that reproduces this?
It isn't hard to write a JSON encoder, so you could also go that route. There are many edge cases, but if you write your own, you might not need to implement everything.
Answers (1)
Rushikesh
on 16 Aug 2024 at 8:45
I can see that you have a large table converted to structure type and wants to encode it in JSON. Since the converted data is not ending with “]” or “}”, I assume encoding process was interrupted or failed to process the entire data set.
It would be easier to answer if you could provide relevant example data, size of table or structure.
However, you can try following generalized steps based on above interpretation to resolve the error.
1. Split the Data
If your data is too large, you can try splitting your data into smaller chunks, i.e. smaller tables or structures, followed by encoding each separately and then combining JSON strings.
You can refer to discussion of similar question given below to get more idea about data splitting.
2. Check Data Types
There are several limitations when using “jsonencode” function inside MATLAB. You can refer to following documentation on these limitations and ensure that all the data types within your table are supported by “jsonencode”. Unsupported data types might cause the encoding process to terminate prematurely.
If issue seems like memory limilation then try increasing Java Heap Memory in MATLAB preferences.
Please let me know if this helps.
1 Comment
Walter Roberson
on 16 Aug 2024 at 20:49
I have a vague memory that possibly json encoding is limited to 2 Gb ??
See Also
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!