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.

  Be the first to rate this function Log in to vote

Alex Zueiv   Alex Zueiv - Show more from this author
Tashkent

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

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 19 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: