by Jeremy Bante

FileMaker 16 introduced a collection of built-in functions for manipulating data serialized as JSON. This makes it easier for FileMaker applications to interact with many web services. This will also make JSON the de facto standard format for scripts within FileMaker to pass parameters and results to each other, improving code sharing within the FileMaker community.

JSON does not have a broad palette of scalar data types to choose from: text, number, boolean, and null. So I made a handful of custom functions and scripts for sending and receiving typed data with JSON.

The module is hosted on GitHub, or you can download it directly.

3 responses to “FM-JSON Types”

  1. HHenle says:

    Hi Jeremy,

    Nice! – the caveat is that the JSON functions are not supported in runtime

    I probably continue using the MBS plugin instead.

  2. Dale Long says:

    Hi Jeremy,

    This has been an excellent demonstration for me in order to understand JSON and move forward with adopting some better development practices. Thank you so much for sharing this with the community! I also really loved your old #Parameters techniques, which I used before now. But moving forward in FM16 I am embracing the new JSON way of doing things.

    One issue I have run into – in one use case with the Container functions, I had a situation where these functions would be used to read and write to a container, and in the case of an empty container it would insert a JSON error code rather than set the container as empty. I wanted this code to be able to gracefully handle the empty containers, so I made the following modification to the JSONContainerObject function, which seems to be working:

    If ( not IsEmpty ( containerData ) ;

    JSONSetElement ( “{}” ;
    [ “fileName” ; GetContainerAttribute ( containerData ; “filename” ) ; JSONString ] ;
    [ “base64” ; Base64EncodeRFC ( 4648 ; containerData ) ; JSONString ]
    ) ;

    JSONSetElement ( “{}” ;
    [ “fileName” ; Null ; JSONString ] ;
    [“base64” ; Null ; JSONString ]


    With this change, if the container you are reading from is empty, it inserts empty values into the JSON object. So if you then call the JSONGetContainer function to set a container with the data, it will no longer insert JSON errors and will instead just set it to empty, as I had originally planned.

    I think this is a pretty reasonable solution, but I am rather intermediate in skill level and may not be aware of some of the pitfalls here. Please do let me know if I’m making some terrible mistake!

    In the mean time, thanks again for sharing this with the community. It has been extremely useful in expanding my skills for the future of the platform!

  3. Jeremy says:

    Dale, thanks for the idea! I hadn’t thought of empty container input. I updated the code with a tweak only slightly different from what you suggested, which boils down a matter of personal taste as much as anything else — nothing terribly consequential.

Leave a Reply

Your email address will not be published. Required fields are marked *