Format output from jsonencode to make it more human readable

Can someone provide an example to format the output from jsonencode to make it more human readable. I.E. add carriage returns and indentations.

1 Commento

I am sorry that I didn't understand the question clearly. Can you elaborate on your question? You can refer to the jsonencode doc for more examples.

Accedi per commentare.

Risposte (2)

There might be a more efficient way to do this, but this worked well for me.
str = jsonencode(str);
str = strrep(str, ',', sprintf(',\r'));
str = strrep(str, '[{', sprintf('[\r{\r'));
str = strrep(str, '}]', sprintf('\r}\r]'));

1 Commento

Thanks! it worked for me with the following modification:
str = strrep(str, ',"', sprintf(',\r"'));

Accedi per commentare.

Noam Greenboim
Noam Greenboim il 2 Giu 2024
Modificato: Noam Greenboim il 4 Giu 2024
You can use my solution in File Exchange here:
With this function, you can control the indentation parameters and spacing.
As of R2021a or so (but not earlier version), you can call jsonencode with the parameter PrettyPrint, that does what you asked for.

Categorie

Scopri di più su Data Import and Analysis in Centro assistenza e File Exchange

Prodotti

Richiesto:

il 13 Apr 2017

Modificato:

il 4 Giu 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by