Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

In this exercise, we will attempt to illustrate just a sampling of some of the powerful options available to capture AI extraction results.

Setup

Start by opening a new browser window and navigating to https://try.jsonata.org. The page is broken down into 3 main sections. The left-side panel contains the JSON being inspected. The right top panel is the JSONata expression. The right bottom panel is the JSON output, based on the expression and JSON provided.

The default page setup includes some JSON data to get started, and a sample expression as well.

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

You will notice that a basic expression will resemble a spreadsheet formula.

  1. The dollar sign ($) implies a function is being called, in this case, a built in function called sum. As the name implies, the sum function will provide a mathematical sum of the data points within parentheses.

  2. Account.Order.Product is referring to the JSON in the left panel. If you explore that JSON, you will see a tree of data, logically broken down by Account (in this case there is only one), Order (of which there are two), and Product.

  3. By expressing (Price * Quantity) within parentheses, mathematical order of operations will apply and the value returned by the inner expression will be the product of that operation, and this will apply for each item in the set.

  4. By using the sum function against that inner expressions, you wind up adding all of the Price * Quantity operations found, and producing a total amount of 336.36. In the example case, we are operating against the following:

Product

Price

Quantity

Bowler Hat

34.45

2

Trilby Hat

21.67

1

Bowler Hat

34.45

4

Cloak

107.99

1

  1. It can be helpful to deconstruct expressions to better understand how they work. In the example above, remove “$sum(“ from the start of the expression, and remove the last “)” from the end of it. You will notice the output changes significantly from a single value to an array of values.

    image-20240328-174637.png

Square 9 Sample Setup

  1. Clear the expression in the top right panel.

  2. Clear the JSON in the left panel.

To clear the panels, simply select all (Ctrl+A) and hit the delete key.

With the stoe

  • No labels