JSONata Documentation

repository·master·Indexed 25 days ago

https://github.com/jsonata-js/jsonata

JSONata is a lightweight query and transformation language for JSON data, providing a concise syntax for navigating, filtering, and transforming complex JSON structures. It includes a comprehensive set of aggregation, array, and boolean functions, as well as operators for comparison and boolean logic. The library is available for Node.js and browser environments (version 2.2.2).

Tokens
18.1K
Snippets
82
Records
161
Agent score
83%

What's inside JSONata

  1. Report bugs or request enhancements in JSONata

    master

    To report bugs, suspected bugs, or any unexpected behavior, open a GitHub issue. For the best assistance, include a link to the JSONata exerciser containing your source data and expression. You can generate this link using the "Share" function in the top-right of the exerciser.

    To request new features or improvements, please open a GitHub enhancement request issue.

  2. Filter items using Predicates

    master

    You can filter selected items at any step in a location path using a predicate expression in the form [expr]. The expression expr must evaluate to a Boolean. Each item in the selection is tested against the expression: if true, the item is kept; if false, it is removed. The expression is evaluated relative to the current context item.

    Phone[type='mobile']
  3. Perform numeric calculations

    master

    Numeric literals follow standard JSON number syntax. You can perform arithmetic operations on numbers using the following operators:

    • + (addition)
    • - (subtraction)
    • * (multiplication)
    • / (division)
    • % (remainder/modulo)

    Path expressions pointing to numeric values will return those values directly.

  4. Manipulate strings with concatenation and literals

    master

    JSONata supports string literals using single (') or double (") quotes. You can nest one type of quote inside the other without escaping. To combine strings, use the concatenation operator &. This operator is unique because it will attempt to typecast its operands to strings if they are not already strings.

    Key concepts:

    • String Literals: 'string' or "string".
    • Concatenation: Use & to join strings or cast other types to strings.
    • Escaping: Follows standard JSON string rules.
  5. Sort arrays in JSONata

    master

    You can re-order values in an array using two different methods:

    1. $sort() function: A flexible function that supports custom comparator functions.
    2. order-by operator: A convenient syntax used directly within a path expression to sort result sequences in ascending or descending order.