JSONListKeys, JSONGetElementType, and iterating JSON in FileMaker

Intermediate

FileMaker's JSON functions go beyond get/set. Learn how JSONListKeys iterates object keys, how JSONGetElementType identifies value types, and patterns for processing unknown JSON structures.

What you'll learn

  • How JSONListKeys() lists the keys of a JSON object or indices of an array
  • How JSONGetElementType() identifies the type of a JSON value
  • A loop pattern for iterating all keys in a JSON object

JSONListKeys() returns a return-delimited list of keys in a JSON object, and JSONGetElementType() identifies the type of a value — together they enable processing JSON objects whose structure is not fully known in advance.

1/3
1

List all keys in a JSON object

JSONListKeys ( json ; path ) returns a return-delimited list of key names for a JSON object at the specified path. An empty path references the root.

FileMaker Script
Set Variable [ $json ; Value:
  JSONSetElement ( "{}" ;
    [ "name"   ; "Acme Corp"    ; JSONString ] ;
    [ "id"     ; 42             ; JSONNumber ] ;
    [ "active" ; True           ; JSONBoolean ]
  )
]

JSONListKeys ( $json ; "" )
// Returns: "name¶id¶active"

// Count the keys
ValueCount ( JSONListKeys ( $json ; "" ) )
// Returns: 3

// List keys of a nested object
JSONListKeys ( $json ; "address" )

Sign in to track your progress and pick up where you left off.

Sign in to FM Dojo