12-11-2020 12:55 AM
Hello LabVIEW community:
I was searching for such a tool but to no avail. I can probably write this up myself but why re-invent the wheel if it is already there.
The Challenge
--------------------
Each time I submit clean JSON to HTTP web service VIs, the returned body string looks messy featuring no return and/or line-feed characters to help organise those curly brackets.
>>> The attached shows what I am trying to achieve. i.e
GOAL
----------
To convert a messy raw JSON string to a clean and readable one featuring exact same-JSON string.
. . . Is there a VI for this somewhere? See the before and after goal image attached.
Anthony
12-11-2020 11:12 AM - edited 12-11-2020 11:14 AM
Not LabVIEW but online solution. I've used JSON Editor Online. https://jsoneditoronline.org
Paste it into the left pane.
Click to send it to the right pane. (Which lets you edit things if you wanted.)
Click to send it back to the left pane.
Copy it out of the left pane.
The transfer back to the left plane cleans it up.
12-13-2020 02:27 AM
The term you want is "pretty print" or "prettify" and if you search for that, you can find this, for instance:
https://www.vipm.io/package/felipefoz_lib_json_pretty_printer/
I believe the JSON toolkit on LAVA also has a pretty print function.
12-13-2020 02:33 AM - edited 12-13-2020 02:36 AM
JSONtext has a "Reformat" vi that has a optional input to pretty print. It also installs a "JSON Pretty Print" custom probe that makes debugging JSON much easier.
03-12-2022 01:45 PM - edited 03-12-2022 01:45 PM
Well I did not want to add a library just for this, and I always wondered what would go into writing one.
So after some research, I found this SO answer and adapted it.
It's a little buggy on the edges but it still does a pretty good job if the goal is only to "pretty" display.
At some point, I will try and write a better one, but for now this will do.
Hope it helps someone
03-13-2022 12:05 AM
Fixed some bugs
04-12-2022 03:27 AM
Added check if input json string is already prettified to kmurphs version (LV2021).
04-12-2022 05:20 AM
@Anthony_L wrote:
The Challenge
--------------------
Each time I submit clean JSON to HTTP web service VIs, the returned body string looks messy featuring no return and/or line-feed characters to help organise those curly brackets.
The HTTP VIs have no idea about what the contents in the HTTP response is. It could be JSON, XML, JAVA, random text or fully binary data. So they simply return whatever the server responded with. Sometimes the server may have an extra header field that you can add to the request to ask it to return prettyfied data, or it could be an URL parameter you need to add. By default most servers tend to return concise data to reduce the amount of bytes that need to be transfered. Also there is of course always a very big chance that whatever the server may consider "pretty" is totally disgusting to the end user. Those tab wars in source code files do exist. 😁
04-12-2022 05:51 AM
Hey, @hunkel can you save for a previous version of LV and re-upload?
I currently only have LV2020.
03-01-2024 12:44 PM
Hi, here is the LV2015 version.