What is the best way to understand the structure of a new JSON file?

I am doing some work with a number of different api’s, each of which return relatively large, nested JSON files. At the moment, I step through the file by doing something like

Data[[1]] etc.,

However, this seems very clunky, and I am sure there must be a function which lets me understand the structure much more quickly.

So, I am hoping someone with more experience can explain how they tackle the problem.

Cheers
Andy

You should be able to read JSON into an Association. Which function(s) are you using to access the API (e.g. URLRead)?

In this particular case, I am Importing[] the files, just because I had downloaded them locally.

Typically, the files have a number of JSON keys describing things like version numbers, license requirements etc., and then there is a ‘data’ key (although the name is often different) with a large list of lists that contain the parts I am really interested in.

My question is whether there is a simple way of visualising the structure when you know nothing about the file. I was wondering if I could perhaps display the keys as a tree plot of some kind, or maybe there is a way to show the structured as an indented list. There are a number of web based tools that can do this sort of thing, and I was hoping that Mathematica had a similar function.

Well, I don’t know how big, complicated, or nested your data is, but you could try Dataset to visualize. I downloaded a sample JSON file from https://support.oneskyapp.com/hc/en-us/articles/208047697-JSON-sample-files . Then,

jsonData = Import[pathToJsonFile, "RawJSON"];
Dataset[jsonData]

example_2_dataset.bmp (501 KB)

I don’t know if that’s the kind of thing you’re looking for. Also, once you’ve imported the data and have an Association, you can use the association-related functions (e.g. Keys).

Isn’t there a published schema for your API?

Oh, that’s brilliant! It’s exactly what I was looking for. I think the problem was that Import brought the file in as JSON, and I should have forced it to RawJSON.

Thanks very much for your help.