[FMP Tip-n-Trick] Hierarchical JSON Viewer / Editor
Hierarchical JSON Viewer / Editor
By Andy Persons & Doug West
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.
•• Download JSONViewer.fmp12 ••
**This article is provided for free and as-is, use, enjoy, learn, and experiment at your own risk – but have fun! eXcelisys does not offer any free support or free assistance with any of the contents of this blog post. If you would like help or assistance, please consider retaining eXcelisys’ FileMaker Pro consulting & development services.
eXcelisys, Inc. is an independent entity and this web site/information/blog post has not been authorized, sponsored, or otherwise affiliated with FileMaker, Inc. FileMaker is a trademark of FileMaker, Inc., registered in the U.S. and other countries.
The post [FMP Tip-n-Trick] Hierarchical JSON Viewer / Editor appeared first on eXcelisys.