File Exchange

image thumbnail


version 1.0.0 (2.6 KB) by Yury Bondarenko
Make MATLAB's jsonencode.m strings more readable


Updated 12 Feb 2021

From GitHub

View license on GitHub

Makes JSON strings (relatively) pretty

Mostly meant for structures with simple strings and arrays; gets confused and !!mangles!! JSON when strings contain [ ] { or }.

Cite As

Yury Bondarenko (2021). prettyjson.m (, GitHub. Retrieved .

Comments and Ratings (3)

Peng Chen

Thank Yury Bondarenko for sharing! Also Thank Martin Hultman for the useful modification.

Martin Hultman

Thank you, this worked really well for me. I also added the following code right before the final strjoin to make it even prettier by adding some spacing after colons and commas (except inside strings).

for i = 1:length(lines)
sublines = split(lines{i}, '"');
for j = 1:2:length(sublines)
sublines{j} = strrep(sublines{j}, ':', ': ');
sublines{j} = strrep(sublines{j}, ',', ', ');
lines{i} = strjoin(sublines, '"');
lines = deblank(lines);


This worked really well fro me. I see that it doesn't handle certain cases, but it worked 100% for me and will work for almost everyone. Thanks for sharing! Sanity restored.

MATLAB Release Compatibility
Created with R2019a
Compatible with R2013a and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!