Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Browse to the expression exercise sample data, and copy / paste it into the JSONata Exerciser’s JSON input panel (left side panel). You can now write expressions that should help you better understand Square 9’s specific implementation of this technology.

Parsing Headers Versus Tables

Data is returned in two discrete sections of a singular JSON response. Header / Footer data (also known as Key / Value pairs) is returned in an element aptly name “header_footer”. This section represents and array of identified keys and values on a page. When you compare the data in this section to the source image, you can quickly identify matching keys and values on the source image to better understand what is found and where it exists.

  • In the JSONata expression panel (top right), type the text “header_footer”. You will immediately notice the JSON output changes, and you now see an array of objects that is reflective of the header_footer section alone.

Tables are more deeply nested due to their complex nature, but targeting the tables section is no different.

  • In the JSONata expression panel (top right), type the text “tables”. You will notice the JSON output changes, this time showing you only an array of table objects.

  • Tables are more complex in that a single page may contain multiple tables. Each table is assigned its own index, starting with zero.

You can target a specific table in a number of ways:

  1. Specify the index of the table in square brackets: tables[0]
    Your output JSON will present only the first table.

  2. Specify the tab_index value of the table: tables[table.tab_index=0]
    The tables object in the response is an array of table objects. Each table object has an element for tab_index, that corresponds to it’s numerical ID. The list of tables and associated id’s always starts at zero.

  3. Target a specific table object by altering the expression: tables.table[tab_index=0].
    With this expression, you again get only one table, but pay careful attention to the JSON output. The way this example is expressed will result in slightly different output. It’s important to understand completely how your expressed output is formed, as it will impact how you write expressions to map any data points.

Find A Specific Header Value

Write an expression that will return the Due Date.

  1. Filter by header/footer values with the expression: header_footer

  2. Further filter the result by expressing only the key Due Date: header_footer[key='Due Date']

  3. Further filter to get the value: header_footer[key='Due Date'].value

To summarize, the complete expressions finds the header_footer section, filters for a key of Due Date, and outputs the value of that key.

It can be useful to “generalize” your key targets with partial matches and case sensitivity. This is handled with regular expressions. If for example you wanted your lookup to be case insensitive, you would provide a case insensitive pattern. Regex is expressed as key ~> pattern.

  • header_footer[key~>/due date/i].value would match “Due Date”, “due date”, or “dUe dAtE”.