JSON is the heart of data manipulation in FileMaker. It is essential for passing information, whether through parameters, API calls, or return statements. At DB Services, we're thrilled about the new JSON capabilities in FileMaker 2024!
Enhanced JSONGetElement Functionality
One common task in JSON handling is retrieving the last value of a JSON array, which can be crucial in scenarios such as arrays sorted by date or price. Prior to the release of FileMaker 2024, FileMaker lacked a straightforward method for this. Developers typically used:
JSONGetElement ( "[1,2,3,10]", ValueCount( JSONListValues ( "[1,2,3,10]" , "" ) ) - 1 )
or
JSONGetElement ( "[1,2,3,10]", ValueCount( JSONListKeys ( "[1,2,3,10]" , "" ) ) - 1 )
Both approaches return 10
but are cumbersome. FileMaker 2024 introduces a cleaner solution using:
JSONGetElement ( "[1,2,3,10]", "[:]" )
This new syntax directly retrieves the last value of the array, making the process simpler and easier to remember.
Enhanced JSONSetElement Functionality
FileMaker 2024 also brings improvements to the JSONSetElement
function with the introduction of the +
and :
symbols. Previously, creating and appending elements to an array required complex constructs like:
This would yield [{"a":5,"b":6,"c":7},{"d":8}]
. With the new updates, developers can now create and modify arrays more succinctly:
Creating a new array with a single element using +
could look like:
JSONSetElement ( "[]" , ["[+].a" ; 5 ; JSONNumber] )
Which results in: [{"a":5}]
Similarly, adding to the array using :
could look like:
JSONSetElement ( "[]", ["[+].a"; 5; JSONNumber], ["[:].b"; 6; JSONNumber], ["[:].c"; 7; JSONNumber], ["[+].d"; 8; JSONNumber] )
Which results in: [{"a":5,"b":6,"c":7},{"d":8}]
These new features can also be used within loops for dynamic array manipulation:
which results in: [{"a":5,"b":6},{"a":6,"b":7},{"a":7,"b":8},{"a":8,"b":9}]
JSONMakeArray()
A highly anticipated addition to FileMaker 2024 is the JSONMakeArray()
function. This function simplifies the creation of JSON arrays from a list of values, making it incredibly versatile and efficient. The syntax for JSONMakeArray()
is:
JSONMakeArray ( listOfValues ; separator ; type )
The listOfValues
is a string containing the values, separator
is the character or symbol that separates these values, and type
specifies the object type (e.g., JSONNumber
). This separator can be almost anything, such as letters, numbers, parentheses, or symbols.
Here are some exciting examples of how JSONMakeArray()
can be used:
JSONMakeArray ( "5-6-7-8-9"; "-"; JSONNumber )
Results in
[5,6,7,8,9]
JSONMakeArray ( "5/6/7/8/9"; "/"; JSONNumber )
Results in
[5,6,7,8,9]
JSONMakeArray ( 80030405; 0; JSONNumber )
Results in
[8,0,3,4,5]
(Note that the0
in the array still shows up even though it is marked as a separator)
JSONMakeArray ( "4(5(6(7"; "("; JSONNumber )
Results in
[4,5,6,7]
JSONMakeArray ( List ( 1;2;3;4); "¶"; JSONNumber )
Results in
[1,2,3,4]
(Note that a variable of a list can be used instead of the actual list function as well)
Why These Changes Matter
JSON is integral to FileMaker development and is used extensively for data parsing and transfer. Simplifying complex functions enhances development efficiency and opens up new possibilities for innovative applications. The improvements in FileMaker 2024 significantly streamline JSON handling, making development faster and more intuitive. These new features promise to make JSON manipulation in FileMaker more powerful and accessible than ever before.
If you have any questions regarding these updates in FileMaker 2024, please reach out to us at DB Services and we would be happy to help!
Did you know we are an authorized reseller for Claris FileMaker Licensing?
Contact us to discuss upgrading your Claris FileMaker software.