JSON in "pretty" format?

Post your questions and help other users.

Moderator: Martin

Post Reply
lord_EarlGray
Posts: 19
Joined: 16 Jun 2018 21:17

JSON in "pretty" format?

Post by lord_EarlGray » 09 Jul 2018 17:07

Hi,

Is there any way to log JSON http response in pretty format? I have occasionally problems with parsing JSON and I can't find reason when it is logged in one line.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: JSON in "pretty" format?

Post by Desmanto » 09 Jul 2018 17:51

Automagic already has function to convert back-thru from JSON to Map object and vice versa. The JSON converted will be indented (pretty format). So you can nested this to the response.

Code: Select all

pretty = toJSON(fromJSON(response));
fromJSON() will convert the response to map/list object. toJSON() will convert it back to JSON, but in indented version (pretty format).

But if you only need to check the value only (just to help with reading only), you can simply put condition debug dialog after the response. Then find the response > Show value in text editor > 3 dot menu > Format JSON. This only change the view only, but doesn't change the real response value as the one above.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

lord_EarlGray
Posts: 19
Joined: 16 Jun 2018 21:17

Re: JSON in "pretty" format?

Post by lord_EarlGray » 09 Jul 2018 18:05

That works perfect for me! Thanks!

Post Reply