Step-by-Step Guide
Example: Processing API Data
In this example, we will process data retrieved from an API, calculate additional attributes (like the birth decade), and generate a visual chart.
Step 1: Retrieve API Data
Use a REST node to fetch data from an API endpoint. For example:
{ type: 'rest', url: 'https://randomuser.me/api/?results=3 children: [ {type: 'json'} ] }
This will generate data for 3 people.
Inspect the initial data structure.
Debugging and Context Exploration
Enabling Debug Mode
Toggle debug mode to view additional buttons for inspecting the report context.
Use the Inspect option in your browser developer tools to access the console.
Explore the JSON context at various levels:
Root context: Contains global data sources and metadata.
Node context: Contains data specific to the current processing node.
Tips and Best Practices
Start Small: Begin with simple queries to understand the structure of your data.
Leverage Debug Mode: Use the debug tools to trace errors and verify transformations.
Utilize Functions: JSONata provides a wide range of built-in functions for advanced data manipulation.
Reuse and Optimize: Store reusable queries in variables to simplify and optimize transformations.
Common Functions in JSONata
Function | Description | Example |
---|---|---|
| Maps a function to each element in an array. |
|
| Filters elements based on a condition. |
|
| Merges objects into a single object. |
|
| Returns unique values from an array. |
|
| Sorts an array. |
|
| Counts elements in an array. |
|