Brian Dunning's FileMaker Custom Functions

@JsonFixElement ( serialNum ; param )

A helper for the native function JSONSetElement() to force objects appear in the order you set them.

  Average rating: 5.0 (1 vote) Log in to vote

Alex Zueiv   Alex Zueiv - Show more from this author
Tashkent
https://github.com/zueiv

Share on Facebook Share on Twitter

  Sample input:
List (

"native: " & JSONSetElement ( "" ; [ "b" ; 1 ; 0 ] ; [ "a" ; 2 ; 0 ] ) ;

"---" ;

"fixed: " & Let (
    JSN = JSONSetElement ( "" ;
        [ @JsonFixElement ( 1 ; "b" ) ; 1 ; 0 ] ;
        [ @JsonFixElement ( 2 ; "a" ) ; 2 ; 0 ]
    ) ;
    List (
        @JsonFixElement ( 0 ; JSN ) ;
        @JsonFixElement ( 0 ; JSONFormatElements ( JSN ) )
    )
)

)
  Sample output:
native: {"a":2,"b":1}
---
fixed: {"b":1,"a":2}
{
    "b" : 1,
    "a" : 2
}

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

A helper for the function JSONSetElement(). Fixes objects in the order you set them.

Allows to build JSON requests for APIs like Authorize.Net that requires the ordering of elements to match the API Reference (see https://developer.authorize.net/api/reference/).

Non-recursive. Requires FM 16 or greater (no runtimes).

Can be used with another my wrapper CF to produce an aligned JSON structure with a custom object sort order:

@JsonFixElement ( 0 ; @JsonFormatElements ( fixedJSON ) )

https://www.briandunning.com/cf/2130

 

Comments

Frederic Bruckert   Frederic Bruckert
Apr 8, 2024
Great ! !! Thanks you so much. This CF is so important to keep order in json object when we retrieve datas from Filemaker, to display them in ordered tables on a web site.
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: