Search code examples
jsonfilemaker

How do you get the first element out of a JSON String without knowing the name of the element in FileMaker 16 or 17?


I had an issue today with Filemaker on how to get the first element out of a json result without knowing the key.

Example $json result from an API call

{
    "26298070": {
        "task_id": "26298070",
        "parent_id": "0",
        "name": "DEPOT-0045 Research ODBC Model Extraction via Django To cut down on development time from Filemaker to Postgres",
        "external_task_id": "32c8fd51-2066-42b9-b88b-8a2275fafc3f",
        "external_parent_id": "64e7c829-d88e-48ae-9ba4-bb7a3871a7ce",
        "level": "1",
        "add_date": "2018-06-04 21:45:16",
        "archived": "0",
        "color": "#34C644",
        "tags": "DEPOT-0045",
        "budgeted": "1",
        "checked_date": null,
        "root_group_id": "91456",
        "assigned_to": null,
        "assigned_by": null,
        "due_date": null,
        "note": "",
        "context": null,
        "folder": null,
        "repeat": null,
        "billable": "0",
        "budget_unit": "hours",
        "public_hash": null,
        "modify_time": null
    }
}

I tried JSONGetElement( $json, "") and got the original json. I tried JSONGetElement( $json, ".") and got the original json. I tried JSONGetElement( $json, 1 ) and got nothing.

How do you get the first element out of a JSON String without knowing the name of the element in FileMaker 16 or 17?


Solution

  • Try this for the root element:

    JSONListKeys ( $json ; "" )

    result: 26298070 Once you get the root, you can get the child keys.