Format output from jsonencode to make it more human readable

17 次查看(过去 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
编辑: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]'));

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 中查找有关 Programming 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by