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.
Example:
- .QueryResponse.Customer[0].Taxable
- .QueryResponse.Customer[0].domain
- .QueryResponse.Customer[0].sparse
- .QueryResponse.Customer[6].Fax
- .QueryResponse.Customer[6].Fax.FreeFormNumber
- .QueryResponse.Customer[6].Mobile
- .QueryResponse.Customer[6].Mobile.FreeFormNumber
- .QueryResponse.Customer[6].WebAddr
- .QueryResponse.Customer[6].WebAddr.URI
- .QueryResponse.Customer[7].Level
- .QueryResponse.Customer[7].ParentRef
- .QueryResponse.Customer[7].ParentRef.value
- .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:
- 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.
- 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.
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.
brian@scarpettagroup.com