Technologies
JSONata
Explains JSONata as a JSON query and transformation language used in Stubber. Useful for filtering, reshaping, extracting, and composing data in actions and substitutions.
JSONata is a powerful and flexible query and transformation language designed specifically for JSON data. It provides a way to filter, transform, and extract data from JSON structures, making it an invaluable tool for developers working with APIs, databases, or any system that uses JSON.
Key Features
Querying JSON Data
JSONata allows you to select specific parts of a JSON document using a simple and expressive syntax. For example, you can retrieve all items in a list that match certain criteria.
Transforming JSON Data
Beyond querying, JSONata enables you to transform JSON data. You can restructure data, create new fields, or modify existing values as needed.
Filtering Data
JSONata's filtering capabilities let you define complex conditions to include or exclude data based on various criteria. This is particularly useful for extracting relevant information from large JSON datasets.
Function Support
JSONata includes a variety of built-in functions for performing common tasks such as string manipulation, arithmetic operations, and date handling. You can also define your own custom functions to extend its capabilities.
Chaining and Composition
JSONata expressions can be chained together to perform multiple operations in a single query. This makes it possible to create complex data transformations in a clear and concise manner.
Uses in Stubber
JSONata is used throughout Stubber to enable more advanced functionality in certain areas:
- Value replacement via the JSONata Hashtag Helper
- The savedata task, for more advanced data manipulation
- Conditions arrays
- Validations
Writing JSONata
The best way to learn JSONata is to use the JSONata Playground. You can copy and paste the context data into the playground, then write your JSONata query in the expression box.
A common mistake with JSONata is to try to do dynamic path lookups eg. stub.data.people[stub.data.current_person].name
This is not possible with JSONata you need to use the $lookup function to achieve this.
Eg. $lookup(stub.data.people, stub.data.current_person).name