Extract from JSON processor

Patrick Smith Updated by Patrick Smith

The Extract from JSON processor extracts the values wrapped in a JSON object in order to create new fields.

When to use this processor?

Your source data is located in a JSON format. When previewing your dataset, you see that instead of values, your fields contains data wrapped in curly brackets, meaning that the data is contained within JSON objects. You therefore need to extract the values contained in these JSON objects for them to surface properly.

How to fill it in

The processor is made up of two boxes only:

  • Field: A drop-down menu contains the titles of the different fields of the dataset. Select the field that contains the JSON object from which the values must be extracted.
  • Ijson rules: In this box, you will need to write down an iJSON rule to indicate the path to the values to extract. How to build it? An iJSON rule is built with the names of all the fields from the JSON root to the data to extract, separated with a dot. Let's see with some examples.

An example

{ "name": "Joe",
"features" : {
"hair" : "blond",
"eyes": "brown",
"genre": "male",
"married": false
},
"contact" : { "email" : "joe.joe@gmail.com"}
}

We need to build a dataset from this JSON file. We need to have the following fields: name, hair, eyes, genre, married, and email. Use the processor Extract from JSON:

  • To extract the value Joe in a new field called "name", write the iJSON rule name
  • To extract the value blond in a new field called "hair", use the iJSON rule features.hair
  • To extract the value brown in a new field called "eyes", use the iJSON rule: features.eyes
  • To extract the value joe.joe@gmail.com use this rule: contact.email
  • If you use the rule features, you will get the following dataset schema. But, you will not get the values that are listed in the higher hierarchy of object (name, contact).
{
"hair" : "blond",
"eyes": "brown",
"genre": "male"
}

ODS Academy tutorial

The following video gives an example of when to use the processor Extract from JSON.

The NASA API is used to create a dataset listing photos of Mars, taken by the rover "Curiosity". Place the following API call as source to a new dataset https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?sol=2000&api_key=DEMO_KEY

With this request, we display the images taken by the Curiosity rover during "sol" 2000. (A sol is a measure of time on Mars, somewhat similar to a day on Earth. More info here if you’re curious to learn more.)

How did we do?

Extract bit range processor

Extract text processor

Contact

Powered by HelpDocs (opens in a new tab)