Borrar filtros
Borrar filtros

Format output from jsonencode to make it more human readable

17 visualizaciones (últimos 30 días)
Sonoma Rich
Sonoma Rich el 13 de Abr. de 2017
Editada: Noam Greenboim el 4 de Jun. de 2024
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 comentario
Swathik Kurella Janardhan
Swathik Kurella Janardhan el 20 de Abr. de 2017
Editada: Swathik Kurella Janardhan el 20 de Abr. de 2017
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.

Iniciar sesión para comentar.

Respuestas (2)

jcbyts
jcbyts el 8 de En. de 2019
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 comentario
Payam Razavi
Payam Razavi el 8 de Dic. de 2020
Thanks! it worked for me with the following modification:
str = strrep(str, ',"', sprintf(',\r"'));

Iniciar sesión para comentar.


Noam Greenboim
Noam Greenboim el 2 de Jun. de 2024
Editada: Noam Greenboim el 4 de Jun. de 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.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by