> For the complete documentation index, see [llms.txt](https://api.qvalia.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://api.qvalia.io/qvalia-developer-tools/json-xml-or-json-to-xml.md). Agents can also search and read this documentation through its [MCP server](https://api.qvalia.io/~gitbook/mcp).

# JSON/XML or JSON to XML

As we support both the Peppol UBL and XML standards you can freely choose between then, and even mix them, with creating a message as XML but fetching it using JSON, or the other way round.

The response, in JSON, will always include the three latest messages, per default. Using XML you always only get one (as there's no "array" function for XML). For JSON, use the\
`limit` parameter to change the number of returned messages, combined with `offset` to page through your messages.

{% hint style="success" %}
With JSON data we add the `integrationId` attribute (the unique identifier in our DB) into the JSON object, as, with JSON, you can get an array of objects and then each object has its own unique `integrationId`.

With XML we only return one message at a time in the original XML format and because of this the `integrationid` will be returned as a HTTP response header (and please note that HTTP headers are case-insensitive, meaning the returned ID will be `integrationid` in all lowercase letters!)
{% endhint %}

#### Choosing a format <a href="#choosing-a-format" id="choosing-a-format"></a>

| You send                                       | You get |
| ---------------------------------------------- | ------- |
| `content-type: application/json`, no `accept`  | JSON    |
| `content-type: application/xml`, no `accept`   | XML     |
| any `content-type`, `accept: application/json` | JSON    |
| any `content-type`, `accept: application/xml`  | XML     |

`accept` overrides, so you can POST XML and receive JSON. Omit both and you get JSON.

### Transformation between JSON and XML <a href="#transformation-between-json-and-xml" id="transformation-between-json-and-xml"></a>

Our API is developed closely to the UBL and Peppol specifications why we've opted to include both the `XML` and `JSON` representations of the formats.

The two representations are "interchangeable" through a transform but if you are a "Node.js" shop you should opt for the `JSON` format. Other programming languages might have an easier time to work with XML instead.

Using the `npm` module xml2js you can transform between `JSON` and `XML` as the format is bi-directional.

```javascript
const xml2js = require('xml2js');
// Convert from JSON ->> XML
const convertUblJsonToUblXml = async (json) => {
  const builder = new xml2js.Builder();
  return builder.buildObject(json);
};
// Convert from XML (string) ->> JSON
const convertUblXmlToUblJson = async (xmlString) => {
  const parser = new xml2js.Parser({ explicitArray: true, explicitCharkey: true });
  return parser.parseStringPromise(xmlString);
};
```

### Limit <a href="#limit" id="limit"></a>

The XML has no “envelope” so we only ever return one message, meaning the `limit` parameter is set to `1`. Using JSON you can set any limit you like, but the response size is limited to 6 MB.

For JSON, we return the `integrationId` as part of the message, while with XML you'll find it as a returned HTTP header named `integrationid`. When you do a `POST` (creating something) we return the message about the message created along with the `integrationId`.

The `integrationId` is the unique identifier for the message in our database and you can store that as an external permanent link to the message with us.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://api.qvalia.io/qvalia-developer-tools/json-xml-or-json-to-xml.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
