JSON Data -> Pretty JSON Tool for Tinderbox readability and import

Hi everyone, i’m retrieving a text data and i need to show it in like a json pretty format.

ex: i have this

[{“Example1”:“test1”,“Example2”:“test2”,“Example3”:“test3”}]

that is a text data type

and i need that looks like this

[
{
“Example1”:“test1”,
“Example2”:“test2”,
“Example3”:“test3”
}
]

Is there a way to do this in Tinderbox or do you use another json tool before import?
In last weeeks demo, I noticed @eastgate showed us “pretty json” format to work with json files.

Although the solutions work with either format, “pretty json” format is much easier to read.

Thanks in advance

Tom

Tom, give me 10 minutes, and I’ll give you the template. You can also watch last week’s meetup, where we reviewed this exact use case.

If it’s just cleanup of raw JSON you need, then search for JSON formatters – there a lots of web and desktop tools for that, many of them free.

At play here, I think, is the fact that you can likely use runCommand() to send your non-pretty code from $Text to an online prettifier and use the result to replace the $Text with the ‘formatted’ version.

Thanks Paul, MarkA and MichaelB

My preference is to use a local tool. I checked at the app store and have found a couple of tools, one to validate then one to “prettify” . Ok but not perfect. Would love to “prettify” in Tinderbox with a template.

@satikusala can you post the template you referred to here for all.

The session last week on JSON was “excellent” but had to jump off after Mark’s part. I will review probably “pretty” manana. :slight_smile:

Tom

  1. Assume the string is in $Text.
  2. Apply stamp
  3. Apply template
  4. Look at “Export” to see the output.

JSONTempalte.tbx (138.8 KB)

Polite observation: the stamp is a bit hard to spot as there is no /Hints and the stamp has not been named so is listed as ‘stamp name’.

The $Feed holds data using typographic quotes which are not ‘legal’ in JSON. Doubtless an unintended copy paste/artefact, but likely to cause confusion.

Rather than as shown, it think the correct ‘pretty’ print would look more like this:

JSON Formatter & Validator 2024-11-09 18-09-00

The main difference is that nested items are indented.

As said a ‘polite’ note, I’m not being negative about using a action code to do this task. :slight_smile:

2 Likes

Thanks! Yup, I just did a quick POC. :slight_smile:

1 Like

Thanks Paul.

Just for followup for members of the community, the tool I am currently using from the Mac App Store is JSON Editor to validate and prettify json with a single tool.

-local
-validates the file
-prettifies json via Format/Format JSON/JSON5

for now, it does what I need.

Tom

Which one? There is a free one, a $7.99 one…?

I am using / trying both of these. There are many others, but these are the two I initially started with

Nothing flashy with JSON editor, just works but need to go to Format/JSON Format/JSON5 to get the prettifier.
-decent validator as well

OK JSON
-won’t import for me unless its properly formatted, but has scripts you can use. I bought it to practice and save scripts.

Tom

1 Like