Format output from jsonencode to make it more human readable
조회 수: 18 (최근 30일)
이전 댓글 표시
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
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
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
2020년 12월 8일
Thanks! it worked for me with the following modification:
str = strrep(str, ',"', sprintf(',\r"'));
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!