18 Sep 2022 – these custom functions have been upgraded – see JSON Custom Functions for FM 19.5, part 2 for details.
Disclaimer: the technique shown in this article is provided on an as-is basis. Use with appropriate caution and at your own risk.
Demo file: JSON-Array-Custom-Functions.zip (requires FM 18 or later)
Have you ever noticed that FileMaker does not provide a JSON function to insert a new element into an existing array? For example, given this array (and bearing in mind that JSON uses a zero-based index)…
[ “A” , “B” , “C” , “D” ]
…JSONSetElement ( array ; 2 ; “XXX” ) will transform it to…
[ “A” , “B” , “XXX” , “D” ]
… but we have no native JSON function to “push” a new element into position 2 so that existing elements slide one position rightward to accommodate, like so:
[ “A” , “B” , “XXX” , “C” , “D” ]