APIs and automation

JSON and XML for integrations: how to prepare files that APIs can consume without breaking the flow

A practical guide to normalizing JSON and XML before transforming, sharing, or sending them to an API without causing avoidable errors.

Apification
Normalized JSON and XML file before being sent to an API

A valid file is not always ready to be integrated

The first mistake in many integrations is confusing correct syntax with a fulfilled contract. A JSON file can follow the grammar defined by RFC 8259 and still not contain the fields an API needs to create a customer, update an order, or publish a catalog. The same happens with XML: it can be well-formed, with correctly nested tags, but not match the schema or semantic rules expected by the receiving system.

Before automating, it is useful to separate three questions. The first is whether the file can be read as JSON or XML. The second is whether its structure matches the expected schema. The third is whether the data makes sense for the business process. An order with perfect syntax but no product identifier can fail just like a malformed file; the difference is that the failure will appear later and be harder to debug.

  • Format: the parser can open the file without syntax errors.
  • Contract: the fields, types, and hierarchies match what is documented.
  • Content: the values are acceptable for the operation the API will execute.
A valid file is not always ready to be integrated

Choose JSON or XML based on the consumer, not preference

JSON is usually convenient when the consumer works with objects, arrays, strings, numbers, booleans, and nulls. Its type model is defined directly: a value can be an object, array, number, string, boolean, or null. That is why, if a field called id sometimes arrives as a number and other times as text, the problem is not aesthetic; it is an inconsistency that forces the receiver to guess rules that should be documented.

XML fits well when the receiving system already works with XML vocabularies, document structures, attributes, namespaces, or legacy contracts. XML allows custom tags to be defined and formally distinguishes between elements and attributes as name-value pairs associated with elements. When mapping XML to JSON, that difference matters: an attribute should not disappear or be confused with a child of the element if the destination contract needs it.

  • Choose JSON if the expected contract is expressed in objects, arrays, and simple types.
  • Choose XML if the receiver requires an XML vocabulary, attributes, namespaces, or a schema-based XML contract.
  • Do not convert for convenience if the consuming system already imposes a format.
Choose JSON or XML based on the consumer, not preference

Minimum checklist before transforming or sending

Encoding should be checked from the start. For JSON exchanged between open systems, RFC 8259 requires UTF-8. In XML, RFC 7303 recommends UTF-8 for the XML media types defined by that specification. If the file travels over HTTP, using the correct extension is not enough: Content-Type and Content-Encoding indicate how the representation should be interpreted, and the sender should generate Content-Type when sending content unless it does not know the media type.

It is also worth aligning the extension, the actual content, and the MIME type. For JSON, the registered type is application/json; for generic XML, it is application/xml. A file called data.json that contains XML, or a request with an incorrect Content-Type, can cause errors before any business rule is evaluated. In repeatable integrations, this check should be part of the preflight control, not later debugging.

  • Confirm UTF-8 before processing.
  • Check the file extension and actual content.
  • Use application/json for JSON and application/xml for generic XML.
  • Review Content-Type and Content-Encoding when sending over HTTP.
  • Verify that there is a clear root structure and documented required fields.

Field names and types: stability over creativity

An API needs stability. Changing customer_name to customerName halfway through a flow, mixing languages, or using ambiguous abbreviations forces exceptions to be maintained. It is better to choose one convention and keep it: names without spaces, clear meaning, and a documented correspondence with the source system. If the file is transformed, the mapping should indicate where each field comes from and how it is named in the output.

Stability also affects types. In JSON, true, false, and null must be written in lowercase; True, FALSE, or NULL are not JSON compliant with the RFC. In addition, the same field should not alternate between number, string, object, or array without an explicit rule. An identifier such as 00123 should be treated as text if those zeros are part of the value; if it is converted into a number, relevant information for the system consuming it will be lost.

  • Avoid spaces and language changes in field names.
  • Do not reuse the same field for different meanings.
  • Keep identifiers as text when the exact format matters.
  • Do not alternate between array, object, string, or number in the same field without documenting it.
  • Use true, false, and null in lowercase in JSON.

Common errors that break apparently simple flows

Many failures do not appear in the first test record. A catalog can include a single product as an object and several products as an array; the receiver always expects an array and fails when the cardinality changes. An optional field can appear as null, as an empty string, or be omitted entirely; each option can have a different meaning if the contract does not clarify it. Preparing JSON and XML for integrations means deciding these rules before the file enters production.

Dates are another critical point. RFC 3339 defines a date-time format for Internet protocols with a full date, T separator, full time, and time zone as Z or a numeric offset. A local date without a time zone can be ambiguous if the contract expects Internet timestamps with an offset. In XML, in addition, a closing tag out of order breaks well-formedness, and namespaces are not decoration: name comparison depends on the associated namespace, not only on the visible prefix.

  • Leading zeros lost when identifiers are converted into numbers.
  • Arrays converted into objects when there is only one item.
  • Optional values represented in several ways without a common rule.
  • Local dates without a time zone when the receiver expects RFC 3339.
  • XML namespaces treated as decorative text during a conversion.

Validate format, content, and business separately

The most useful validation classifies errors. Format errors prevent the file from being read: malformed JSON, XML with incorrectly nested tags, or JSON literals written in uppercase. Content errors appear when the file can be read but does not meet documented types, required fields, or constraints. Business errors occur when the data is structurally correct, but the operation is not acceptable to the consumer.

For JSON, JSON Schema allows teams to work with schemas written in JSON, and its specification is divided into Core and Validation. Declaring $schema helps communicate to readers and tools which version is intended to be used. For XML, use the schema or documented rules supplied by the consumer when available. These tools and rules do not replace the functional contract of an API, but they help turn expectations into checks before sending the file.

  • Format: the document can be parsed as JSON or XML.
  • Content: fields, types, and constraints match JSON Schema, an XML schema, or documented rules.
  • Business: the receiver accepts the operation with those specific values.
  • Debugging: record a minimal example that reproduces the failure.

Transform safely: original, output, and versions

A safe transformation never destroys the input file. Keep the original, generate a transformed output, and compare differences before sharing or automating. This makes it possible to answer basic questions when something fails: which file arrived, which rule was applied, which output was generated, and which version was sent. If the mapping changes, it should be versioned like any other critical element of the flow.

In Apification, this approach fits with Cloud: you can organize files, services, and digital projects in a versioned space designed for sharing. You can also review the history of a Cloud item, download previous versions, and restore content safely. When files need to be transformed, the guided assistant can convert, split, merge, optimize, and process documents, images, video, audio, and data; the specific validation of the external contract still depends on the rules or schemas the team has defined.

  • Always save the original file received.
  • Generate a new output; do not overwrite without control.
  • Name input, output, and mapping versions.
  • Compare samples before automating deliveries.
  • Keep a minimal reproducible sample for debugging.

Where Apification fits in the integration flow

Apification can provide organization and operations around the file. Teams can store originals and outputs in Cloud, share items through links, users, or groups, and provide original or transformed downloads. If the flow starts in forms, it is also possible to create questionnaires and capture forms with validation, access controls, and exportable responses, which helps reduce variations before the data becomes JSON or XML.

When the process needs to connect with other systems, Apification allows Cloud and its services to be integrated through REST API, OpenAPI, webhooks, iframe, and JavaScript. Cloud actions can be connected through APIs and signed webhooks with retries, history, and statistics. The practical decision is clear: use Apification to organize, transform, share, and connect the flow; use JSON Schema, XML schemas, or the consumer’s documented rules to validate the specific contract required by the external API.

  • Cloud to organize original files, transformed files, and projects.
  • Transformation assistant to process data and other files when applicable.
  • REST API and OpenAPI to integrate Cloud services.
  • Signed webhooks to connect actions with retries, history, and statistics.
  • Permissions, OTP, external authentication, restrictions, and publishing windows to protect access.

Frequently asked questions

Is valid JSON already ready to be sent to an API?

Not necessarily. Valid JSON means it follows the format syntax, but the API may require fields, types, dates, and business rules that are not defined by RFC 8259.

When should XML be used instead of JSON?

XML should be used when the consuming system requires XML vocabularies, attributes, namespaces, schema-based XML contracts, or compatibility with legacy XML-based contracts.

What encoding should I use for JSON and XML integrations?

For JSON exchanged between open systems, UTF-8 must be used. In XML, UTF-8 is a recommended encoding for the XML media types defined by RFC 7303.

Does Apification validate any external JSON Schema or XML schema?

Apification helps organize, transform, share, and connect files and services. Validation of the specific contract of an external API should be based on the JSON Schema, XML schema, or rules documented by that consumer.

What should I keep to debug an integration failure?

Keep the original file, the transformed output, the version of the mapping or rule applied, relevant headers such as Content-Type, and a minimal sample that reproduces the error.

Sources and further reading

Documentation consulted while preparing this article.

Explore Apification

Related articles

APIs and automation

Integrate embedded Cloud without exposing credentials

A practical guide to embedding Apification Cloud with an iframe, REST API, and mediator backend while keeping credentials, permissions, and sensitive actions out of the browser.

Read article
Back to the blog