We live in an API economy, surrounding ourselves with technologies built upon REST APIs. Social media, online shopping, internet banking, and Software as a Service all rely on exchanging data through REST API, and JSON is increasingly becoming the data format of choice.

Developers who interact with REST APIs can end up writing lots of code to navigate through JSON structures to find the data values they need. Making this code robust enough to deal with missing data or sophisticated enough to cross reference or aggregate data can require a developer to write hundreds of lines of code.

There has to be an easier way. With JSONata, there now is an easier way.

JSONata is to JSON what XPath is to XML. And, like the latest versions of XPath, it is much more than just a path navigation syntax. JSONata is a full-expression language with a rich complement of operators and functions, plus the ability to define your own functions. It also has the ability to build JSON output structures containing the results of your queries. In other words, it’s a transformation language.

Head over to https://jsonata.mybluemix.net/ and see it in action. Type in the following JSONata expression:

$sum(Account.Order.Product.(Price * Quantity))

Order and Product are nested arrays. Each product has a price and a quantity and we want to multiply these together for each product within each order, then sum them up to calculate a total order price. In a single expression; no for-loops, ifs or buts. Go play.

Helpful resources

2 Comments on "Introducing JSONata: A query and transformation expression language for your JSON data"

  1. Jamie Jennings October 10, 2016

    This looks awesome! Very powerful but also looks easy to learn (which is quite an achievement).

    And imo, the functional nature is compelling not only to those of us who studied lambda calculus, but also to fans of Scheme, Lisp, Haskell, ML, Lua, and other languages that encourage the use of higher order functions.

  2. Chintan Kadia October 20, 2016

    It’s Awesome.

Join The Discussion

Your email address will not be published. Required fields are marked *