Dataflow Automation Common Questions
Table of Contents
What is JSON?
Before manipulating your data, it is critical to understand how the data are structured. Zerion Dataflows use the JavaScript Object Notation (JSON) to structure data. JSON is a light-weight language-independent way to structure data. This article discusses three critical JSON constructs: key/value pairs, objects, and arrays.
Key/Value Pairs
A Key/Value Pair (KVP) is a pair of data that reference one another. The key is the first value, which is associated with a corresponding value. The key will always be a string (text value); however, the value may be any supported data type.
{"Key":"Value"} // string {"year":2016} // integer {"complete": false} // boolean
Objects
An Object is the fundamental building block of JSON. The simplest explanation is that a JSON Object is a list of KVPs. The list could be zero, one, or many KVPs. Objects are defined by using curly braces {} and may be nested within one another with KVPs separated by a comma.
user = { "name": "Jonathan Hsu", "age": 30, "admin": false, "address": { "street": "123 Main Street", "zipcode": 12345 } }
Arrays
Arrays are a special type of object where values are associated with a number, called an index, instead of a key. Unlike an Object that has no inherent sorting order, an Array is assumed to have sequential indices starting at 0. Arrays are defined using square brackets [] instead of curly braces.
scores = [8,10,7,5.5,9]; console.log(scores[1]); // prints 10
Generally, each array value is of the same type although this does not have to be the case.
Objects vs. Arrays
The difference between Objects and Arrays can be described by an analogy. An Object is similar to a dictionary which is a list of terms and their corresponding definition. An Array is similar to a grocery list where the first item on the list has an index of `0`.
What can be confusing is that arrays may be nested in objects and vice-versa. This is an example of an array inside an object:
user = { "name": "Jonathan Hsu", "age": 30, "admin": false, "address": { "street": "123 Main Street", "zipcode": 12345 }, "languages": ["HTML","Python","JavaScript"] }
Then, we can have this object nested within an array:
records = [{ "name": "Jonathan Hsu", "age": 30, "admin": false, "address": { "street": "123 Main Street", "zipcode": 12345 }, "languages": ["HTML","Python","JavaScript"] }, { "name": "John Doe", "age": 35, "admin": true, "address": { "street": "123 Main Street", "zipcode": 12345 }, "languages": ["PHP","JavaScript","Java"] }]
Additional Resources
For more information on arrays and objects refer to the following articles:
Comments
0 comments
Please sign in to leave a comment.