As we delved into the world of REST APIs using FileMaker, we stumbled across an issue:

How do we handle XML responses?

When the REST response is a JSON object, we don't have any issue — we can make use of the JSON functions introduced in FileMaker 16 to manipulate the response as needed.

However, during our development of fmapi-aws-s3 (a FileMaker AWS S3 integration), we found that many REST APIs respond in XML rather than JSON.

The Solution

This was a problem, and with any problem, solutions are born. We present fm-xml2json.

fm-xml2json is a FileMaker script which, when passed a valid XML string, converts it into a JSON object. This allows you to use FileMaker's native JSON functions to parse and manipulate data from any XML-based REST API.

How It Works

The script accepts a valid XML string as its input parameter. It then recursively parses the XML structure, processing each element and its attributes to build a corresponding JSON object. The hierarchical nature of the XML document is preserved in the resulting JSON, with nested elements becoming nested objects.

Element attributes are extracted and included in the JSON output, ensuring that no data is lost during the conversion. Child elements are processed recursively, so even deeply nested XML structures are handled correctly. Where an element contains multiple child elements of the same name, these are represented as a JSON array, maintaining the one-to-many relationship from the original XML.

The script uses FileMaker's native string manipulation functions to traverse the XML tree and FileMaker's native JSON functions to construct the output. This means the entire conversion happens within FileMaker's scripting engine, with no external dependencies.

Example

Given the following XML input:

<employees>
  <employee id="1">
    <name>Steven McGill</name>
    <role>Developer</role>
  </employee>
  <employee id="2">
    <name>Jane Smith</name>
    <role>Designer</role>
  </employee>
</employees>

fm-xml2json produces the following JSON output:

{
  "employees": {
    "employee": [
      {
        "@id": "1",
        "name": "Steven McGill",
        "role": "Developer"
      },
      {
        "@id": "2",
        "name": "Jane Smith",
        "role": "Designer"
      }
    ]
  }
}

Installation

To get started, download the script from the GitHub repository. Import the script into your FileMaker solution via the Import Scripts option in the script workspace. Once imported, call the script with a valid XML string as the script parameter. Retrieve the resulting JSON using Get ( ScriptResult ).

Use Cases

XML remains prevalent across many APIs and data exchange formats. fm-xml2json is particularly useful in the following scenarios:

  • Parsing REST API XML responses — Not all REST APIs return JSON. When an API responds with XML, this script lets you convert the response into JSON so you can work with it using FileMaker's modern JSON functions.
  • Working with SOAP services — SOAP web services return XML envelopes by design. fm-xml2json allows you to extract and convert the relevant portions of a SOAP response into JSON for easier processing.
  • Processing XML data feeds — RSS feeds, product catalogues, and other syndication formats are typically XML-based. This script enables you to ingest and transform these feeds directly within FileMaker.
  • AWS S3 API responses — As we discovered during the development of fmapi-aws-s3, the AWS S3 API returns XML for operations such as listing bucket contents, retrieving object metadata, and handling multipart uploads. fm-xml2json was born out of this exact need.

Requirements

fm-xml2json requires FileMaker Pro 16 or later, as it relies on the native JSON functions introduced in that version. The script uses JSONSetElement, JSONGetElement, and related functions to construct the output JSON object.

Comparison with Alternatives

Unlike plugin-based solutions, fm-xml2json is written entirely in native FileMaker scripting. This means there is nothing additional to install, no licensing to manage, and no compatibility issues to worry about when upgrading FileMaker. Because it uses only native functions, the script works on FileMaker Pro, FileMaker Server, and FileMaker Cloud — making it suitable for server-side scripts, scheduled tasks, and web-published solutions. It is a lightweight, portable, and dependency-free approach to XML-to-JSON conversion.

Download

The script is available to download free of charge on GitHub.

Related Tool

We also built a CSV-to-JSON parser. Check out fm-csv2json.

Integrating FileMaker with REST APIs? We can help with complex data transformations and API work.

Book a Free Consultation