Filter löschen
Filter löschen

Format output from jsonencode to make it more human readable

22 Ansichten (letzte 30 Tage)
Sonoma Rich
Sonoma Rich am 13 Apr. 2017
Bearbeitet: Noam Greenboim am 4 Jun. 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 Kommentar
Swathik Kurella Janardhan
Swathik Kurella Janardhan am 20 Apr. 2017
Bearbeitet: Swathik Kurella Janardhan am 20 Apr. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

jcbyts
jcbyts am 8 Jan. 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 Kommentar
Payam Razavi
Payam Razavi am 8 Dez. 2020
Thanks! it worked for me with the following modification:
str = strrep(str, ',"', sprintf(',\r"'));

Melden Sie sich an, um zu kommentieren.


Noam Greenboim
Noam Greenboim am 2 Jun. 2024
Bearbeitet: Noam Greenboim am 4 Jun. 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.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by