Have you ever been given a huge block of nested JSON, or you are playing around with an API and you would like to see the keys for what is being returned?
With the introduction of FileMaker 16’s JSON functions and a single script you can get a list of all the unique paths down to each key value pair. This is a recursive script that drills down and generates a list of unique keys based on the JSON it is evaluating.
  1. .QueryResponse.Customer[0].Taxable
  2. .QueryResponse.Customer[0].domain
  3. .QueryResponse.Customer[0].sparse
  4. .QueryResponse.Customer[6].Fax
  5. .QueryResponse.Customer[6].Fax.FreeFormNumber
  6. .QueryResponse.Customer[6].Mobile
  7. .QueryResponse.Customer[6].Mobile.FreeFormNumber
  8. .QueryResponse.Customer[6].WebAddr
  9. .QueryResponse.Customer[6].WebAddr.URI
  10. .QueryResponse.Customer[7].Level
  11. .QueryResponse.Customer[7].ParentRef
  12. .QueryResponse.Customer[7].ParentRef.value
  13. .QueryResponse.Customer[20].MiddleName
The example above is a snippet of the path list that was returned from the script. As we can see above each value is unique. Taxable is found in the first array of customers ( index 0 ). Looking at the list it jumps from Customer index 0 ( QueryResponse.Customer[0]. )  to Customer index 6 (QueryResponse.Customer[6].). The script did not skip the arrays in-between but instead found no unique values that were not already reported in the list above.
The two major ways I feel this tool can be handy are:
  1. Quickly running through a block of JSON and identifying all the unique elements that it contains so you can determine which values you want to extract from the JSON.
  2. Once the full list is generated, it is stored in a global variable and in a field as well. You can go back to this list and copy and paste the path into a JSONGetElement and it will return the result. In the demo file once you paste and parse the JSON there is a button that will open a card window and grab a random value from the generated list of keys and provide the value associated with that key.
I hope this helps simplify some of the JSON and API work people are doing. Feel free to ask any questions or provide feedback.

JSON Path Parsing

I hope you all enjoy the rest of your week and feel free to email with any questions.

– Brian

Brian Ouimette
The Scarpetta Group, Inc.