FileMaker Pro Tip-n-Trick — Hierarchical JSON Viewer / Editor
One of the standout new features of FileMaker Pro 16 is native support for the JSON data-interchange format. In addition to providing easy integration with a host of online services, it also provides developers with the tools to create robust hierarchical structures for use entirely within FileMaker. This hierarchical JSON viewer / editor file provides some tools for visualizing, manipulating, and leveraging JSON text.
- Automatically creates a representation of any JSON text as a hierarchical portal of records, where individual elements can be expanded and collapsed
- Dynamically replicates changes to the hierarchical records in the JSON text, including add, edit, and delete actions
- Highlights the corresponding JSON element when a record is selected
- Easily visualize large JSON text, collapsing nodes to focus on just the relevant sections.
- Manipulate JSON without needing to worry about the correct syntax
- Convert JSON returned from a web service directly into usable Filemaker records, customizing it to your needs
- Create and store hierarchical structures entirely in text (such as global variables), and display it as hierarchical records on the fly
How it Works
- When JSON text is initially entered, the “JSON — Create Children” script retrieves the root keys using JSONListKeys(), loops through the result, and creates the root records.
- When an element is eXpanded, the same script creates its child records if they don’t eXist and eXpands the hierarchy.
- When eXpand All is clicked, a similar script “JSON — Create All Descendants” loops through every element recursively and creates all descendants.
- Values for each record are retrieved and set using JSONGetElement().
- To keep things streamlined, JSON key paths are used for the parent-child keys.
- Records are marked as arrays based on the presence of a left bracket (“[“) and formatted accordingly.
- Since JSONFormatElements() imposes a standard format, elements have a predictable number of leading and trailing lines. These are recorded in lines_leading and lines_trailing, respectively. They are then used in the Highlight Element script to calculate which part of the JSON text should be highlighted when an element record is clicked.