# Canonical Json / XML example with EHRBase **Category:** [Platform](https://discourse.openehr.org/c/platform-implem/7) **Created:** 2021-07-03 11:48 UTC **Views:** 2092 **Replies:** 6 **URL:** https://discourse.openehr.org/t/canonical-json-xml-example-with-ehrbase/1683 --- ## Post #1 by @Ritika_Jain 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 --- ## Post #2 by @venky 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|690x259](upload://eeAOp8kiChBradBA2DtVfzgt2HD.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. --- ## Post #3 by @birger.haarbrandt Hi both, we got some examples in this postman library that is part of the EHRbase documentation: 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: https://github.com/ehrbase/openEHR_SDK 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: 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: 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 --- ## Post #4 by @pablo HI Ritika, you can use the openEHR Toolkit to generate a canonical JSON with random data from an OPT: 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. --- ## Post #5 by @pablo 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. --- ## Post #6 by @Yash Hey @pablo I believe you are talking about 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 --- ## Post #7 by @pablo 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: https://github.com/ppazos/openEHR-OPT --- **Canonical:** https://discourse.openehr.org/t/canonical-json-xml-example-with-ehrbase/1683 **Original content:** https://discourse.openehr.org/t/canonical-json-xml-example-with-ehrbase/1683