Message Boards Message Boards

0
|
631 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

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

Posted 4 months ago

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

POSTED BY: Andrew Burnett
4 Replies
Posted 4 months ago

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

POSTED BY: Eric Rimbey
Posted 4 months ago

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.

POSTED BY: Andrew Burnett
Posted 4 months ago

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]

enter image description here

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?

POSTED BY: Eric Rimbey
Posted 4 months ago

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.

POSTED BY: Andrew Burnett
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract