Format output from jsonencode to make it more human readable

조회 수: 18 (최근 30일)
Sonoma Rich
Sonoma Rich 2017년 4월 13일
편집: Noam Greenboim 2024년 6월 4일
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
Swathik Kurella Janardhan
Swathik Kurella Janardhan 2017년 4월 20일
편집: Swathik Kurella Janardhan 2017년 4월 20일
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.

댓글을 달려면 로그인하십시오.

답변 (2개)

jcbyts
jcbyts 2019년 1월 8일
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
Payam Razavi
Payam Razavi 2020년 12월 8일
Thanks! it worked for me with the following modification:
str = strrep(str, ',"', sprintf(',\r"'));

댓글을 달려면 로그인하십시오.


Noam Greenboim
Noam Greenboim 2024년 6월 2일
편집: Noam Greenboim 2024년 6월 4일
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.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by