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

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

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일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

제품

태그

질문:

2017년 4월 13일

편집:

2024년 6월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by