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 Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by