# Canonical Json / XML example with EHRBase

**URL:** https://discourse.openehr.org/t/canonical-json-xml-example-with-ehrbase/1683
**Category:** Platform
**Tags:** rest-apis, template, json, ehrbase
**Created:** [3 July 2021 11:48 UTC](https://discourse.openehr.org/t/canonical-json-xml-example-with-ehrbase/1683 "2021-07-03T11:48:59Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Ritika\_Jain](https://discourse.openehr.org/user_avatar/discourse.openehr.org/ritika_jain/32/1264_2.png) [@Ritika\_Jain](https://discourse.openehr.org/u/Ritika_Jain)
#### Post date: [3 July 2021 11:48 UTC](https://discourse.openehr.org/t/canonical-json-xml-example-with-ehrbase/1683/1 "2021-07-03T11:48:59Z")

</div>

Hello,

I am just starting with openEHR and EHRBase and trying to post a composition using REST-API  
(POST /ehr\_id/composition) but always get some or the other error. I understand that the api uses canonical json, but I am not able to generate one ( from template) or find any sample. Can someone share a sample template and canonical json or canonical xml, postman collection will be much appreciated. thanks in advance!

Ritika Jain  
Philips Healthcare

---

<div class="post-metadata">

### Author: ![venky](https://discourse.openehr.org/letter_avatar_proxy/v4/letter/v/c89c15/32.png) [@venky](https://discourse.openehr.org/u/venky)
#### Post date: [3 July 2021 12:45 UTC](https://discourse.openehr.org/t/canonical-json-xml-example-with-ehrbase/1683/2 "2021-07-03T12:45:48Z")

</div>

Hi Ritika,

We are also facing similar issue, we posted an OPT template and then posted a JSON with some data, both of which can be found here:  
[Templates and JSON](https://github.com/venkydeo-philips/openEHR_EHRBase)

I am getting a 204 response when i post the Person JSON

And we don’t know how to actually post content for a person, we haven’t found any JSON with content

And for Corona\_Anamnese  
I am getting the following error:

 ![image](https://discourse.openehr.org/uploads/default/original/2X/6/63c4c1038a4b610454296c4e7342ede9569a0591.png)

Even thought the name attribute is present in the request as highlighted.

If this can help you in anyway and you if you find any JSON with content please let me know.

Thanks,  
Venky.  
Philips Healthcare.

---

<div class="post-metadata">

### Author: ![birger.haarbrandt](https://discourse.openehr.org/user_avatar/discourse.openehr.org/birger.haarbrandt/32/24_2.png) [@birger.haarbrandt](https://discourse.openehr.org/u/birger.haarbrandt)
#### Post date: [3 July 2021 16:52 UTC](https://discourse.openehr.org/t/canonical-json-xml-example-with-ehrbase/1683/3 "2021-07-03T16:52:44Z")

</div>

Hi both,

we got some examples in this postman library that is part of the EHRbase documentation: [documentation/examples at master · ehrbase/documentation · GitHub](https://github.com/ehrbase/documentation/tree/master/examples)

Might need an update, but I hope this helps you to get started. In general, I recommend to not build the canonical formats (XML and JSON) by hand, as this is not how it is intended.

Please take a look at the openEHR Software Development Kit:

> **[ehrbase/openEHR\_SDK](https://github.com/ehrbase/openEHR_SDK)**
>
> Contribute to ehrbase/openEHR\_SDK development by creating an account on GitHub.

This includes further examples, especially for the flat formats which are way easier to create from a frontend developers perspective. There is also a function to automatically create DTO classes from openEHR Templates. Please check the documentation for further details: [4. SDK — EHRbase documentation](https://ehrbase.readthedocs.io/en/latest/04_sdk/index.html)

We have an example generator on the roadmap for EHRbase to make beginners life easier. I hope that we can provide this new feature within the next 3 months. In the meantime, you might want to check @pablo’s tools to generate test data: [CaboLabs openEHR Toolkit (CoT)](https://toolkit.cabolabs.com/app/pricing)

Hope this helps 😉

Edit: there is also this postman library with more examples for the flat format [https://discourse.openehr.org/uploads/short-url/seVAphaSVEz2c22d2Ta1VthWX4X.json](https://discourse.openehr.org/uploads/short-url/seVAphaSVEz2c22d2Ta1VthWX4X.json)

---

<div class="post-metadata">

### Author: ![pablo](https://discourse.openehr.org/user_avatar/discourse.openehr.org/pablo/32/3505_2.png) [@pablo](https://discourse.openehr.org/u/pablo)
#### Post date: [4 July 2021 00:15 UTC](https://discourse.openehr.org/t/canonical-json-xml-example-with-ehrbase/1683/4 "2021-07-04T00:15:40Z")

</div>

HI Ritika, you can use the openEHR Toolkit to generate a canonical JSON with random data from an OPT: [https://toolkit.cabolabs.com/](https://toolkit.cabolabs.com/)

I’ve been using it to generate test COMPOSITIONs for EHRBASE and EHRServer for a while now. Note the canonical XML is also an accepted format.

---

<div class="post-metadata">

### Author: ![pablo](https://discourse.openehr.org/user_avatar/discourse.openehr.org/pablo/32/3505_2.png) [@pablo](https://discourse.openehr.org/u/pablo)
#### Post date: [4 July 2021 00:20 UTC](https://discourse.openehr.org/t/canonical-json-xml-example-with-ehrbase/1683/5 "2021-07-04T00:20:40Z")

</div>

Hi Venky, it seems you are posting a VERSION to the COMPOSITION endpoint.

Try to post the COMPOSITION object alone, without the VERSION container.

Also, it seems that JSON is not canonical: is using the XML attributes @xsi:type. That would be accepted in EHRServer but is not accepted in EHRBASE. In EHRBASE you should use canonical JSON or XML, in canonical JSON the @xsi:type would be \_type.

In summary:

1. use COMPOSITION instead of VERSION
2. use canonical JSON or XML

Hope that helps.

PS: maybe EHRBASE is missing some type checking there.

---

<div class="post-metadata">

### Author: ![Yash](https://discourse.openehr.org/user_avatar/discourse.openehr.org/yash/32/1308_2.png) [@Yash](https://discourse.openehr.org/u/Yash)
#### Post date: [21 August 2021 15:45 UTC](https://discourse.openehr.org/t/canonical-json-xml-example-with-ehrbase/1683/6 "2021-08-21T15:45:14Z")

</div>

Hey @pablo

I believe you are talking about [CaboLabs openEHR Toolkit](https://toolkit.cabolabs.com/opt/json_instance_generator) this particular toolkit but for some reason I am not able to post the output composition of this tool. I am pretty sure it is not canonical, can your suggest some other ways to convert templates to flat forms

Thank You

---

<div class="post-metadata">

### Author: ![pablo](https://discourse.openehr.org/user_avatar/discourse.openehr.org/pablo/32/3505_2.png) [@pablo](https://discourse.openehr.org/u/pablo)
#### Post date: [21 August 2021 18:57 UTC](https://discourse.openehr.org/t/canonical-json-xml-example-with-ehrbase/1683/7 "2021-08-21T18:57:38Z")

</div>

I guess you are using the free tools, there there is no canonical json generation, though I should add it.

In the meantime you can use this from the terminal: [GitHub - ppazos/openEHR-OPT: Java/Groovy Support of openEHR Operational Templates, Refernce Model, Dat](https://github.com/ppazos/openEHR-OPT)
