# Extend API to retrieve plain JSON

**URL:** <https://forum.getodk.org/t/extend-api-to-retrieve-plain-json/32204>\
**Category:** Ideas\
**Tags:** odk-central\
**Created:** [January 27, 2021, 11:54am UTC](https://forum.getodk.org/t/extend-api-to-retrieve-plain-json/32204 "2021-01-27T11:54:29Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattelacchiato](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/mattelacchiato/32/14421_2.png) [@mattelacchiato](https://forum.getodk.org/u/mattelacchiato)\
**Post date:** [January 27, 2021, 11:54am UTC](https://forum.getodk.org/t/extend-api-to-retrieve-plain-json/32204/1 "2021-01-27T11:54:29Z")

</div>

**1. What is the general goal of the feature?**  
Enhance the API of ODK central to retrieve submissions in plain JSON format, including repetitions (No OData). This could be achieved with a file extion ".json".

**2. What are some example use cases for this feature?**  
We are using python, which has no active library which supports OData v4 (seems to be quite complex to implement as seen here: [https://github.com/SAP/python-pyodata/issues/39](https://github.com/SAP/python-pyodata/issues/39))  
CSV is not suitable for parsing groups/repetitions...

**3. What can you contribute to making this feature a reality?**  
Currently, we are thinking about extending the ODK central API but would like to ask first if you want to have this. Maybe you've decided explicitly against JSON to prefer OData?

---

<div class="post-metadata">

**Author:** ![Matthew\_White](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/matthew_white/32/1654_2.png) [@Matthew\_White](https://forum.getodk.org/u/Matthew_White)\
**Post date:** [January 27, 2021, 2:44pm UTC](https://forum.getodk.org/t/extend-api-to-retrieve-plain-json/32204/2 "2021-01-27T14:44:05Z")

</div>

Hi @mattelacchiato!

The OData endpoint for submission data should already return a JSON response, for example, something like:

```json
{
  "@odata.context": "https://your.odk.server/v1/projects/7/forms/simple.svc/$metadata#Submissions",
  "value": [
    {
      "__id": "uuid:85cb9aff-005e-4edd-9739-dc9c1a829c44",
      "age": 25,
      "meta": {
        "instanceID": "uuid:85cb9aff-005e-4edd-9739-dc9c1a829c44"
      },
      "name": "Bob"
    },
    {
      "__id": "uuid:297000fd-8eb2-4232-8863-d25f82521b87",
      "age": 30,
      "meta": {
        "instanceID": "uuid:297000fd-8eb2-4232-8863-d25f82521b87"
      },
      "name": "Alice"
    }
  ]
}

```

Is there a different format that you'd expect for the JSON response? For example, including the data from repeat groups?

---

<div class="post-metadata">

**Author:** ![mattelacchiato](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/mattelacchiato/32/14421_2.png) [@mattelacchiato](https://forum.getodk.org/u/mattelacchiato)\
**Post date:** [January 27, 2021, 3:12pm UTC](https://forum.getodk.org/t/extend-api-to-retrieve-plain-json/32204/3 "2021-01-27T15:12:32Z")

</div>

> [@Matthew\_White](#):
>
> For example, including the data from repeat groups?

Exactly! Sorry for the confusion...

---

<div class="post-metadata">

**Author:** ![Matthew\_White](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/matthew_white/32/1654_2.png) [@Matthew\_White](https://forum.getodk.org/u/Matthew_White)\
**Post date:** [January 27, 2021, 3:52pm UTC](https://forum.getodk.org/t/extend-api-to-retrieve-plain-json/32204/4 "2021-01-27T15:52:27Z")

</div>

I could definitely see how that would be useful. Probably the way for us to add that functionality would be to support the OData `$expand` query parameter. We have [a GitHub issue](https://github.com/getodk/central-backend/issues/84) for that, but no timeline at the moment. CC also @issa, who's thought a lot about our OData functionality.

---

<div class="post-metadata">

**Author:** ![mattelacchiato](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/mattelacchiato/32/14421_2.png) [@mattelacchiato](https://forum.getodk.org/u/mattelacchiato)\
**Post date:** [January 27, 2021, 4:04pm UTC](https://forum.getodk.org/t/extend-api-to-retrieve-plain-json/32204/5 "2021-01-27T16:04:31Z")

</div>

For using `$expand`, we would have to now all tables that should get expanded. This is something we would like to avoid and "just dump all data".

I've had a look into the database and saw that the submission\_defs are stored as XML containing the repetitions inside. I guess, an implementation could just stream the submission\_defs XML and convert it to JSON, right?

---

<div class="post-metadata">

**Author:** ![Matthew\_White](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/matthew_white/32/1654_2.png) [@Matthew\_White](https://forum.getodk.org/u/Matthew_White)\
**Post date:** [January 27, 2021, 7:16pm UTC](https://forum.getodk.org/t/extend-api-to-retrieve-plain-json/32204/6 "2021-01-27T19:16:51Z")

</div>

That makes sense, and actually I think OData supports `$expand=*` to expand all tables. You can find some of the implementation for the OData endpoint in `lib/data/json.js`. That file parses the submission XML and formats the data values. I think the next step would probably be to see what changes would be needed to `lib/data/json.js` to support `$expand`. It might also be worth considering just adding support for `$expand=*` for the root table if that would be significantly easier than a more general implementation of `$expand`.

---

<div class="post-metadata">

**Author:** ![mattelacchiato](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/mattelacchiato/32/14421_2.png) [@mattelacchiato](https://forum.getodk.org/u/mattelacchiato)\
**Post date:** [February 1, 2021, 8:58am UTC](https://forum.getodk.org/t/extend-api-to-retrieve-plain-json/32204/7 "2021-02-01T08:58:10Z")

</div>

Thanks, I'll have a look.

If I understand the documentation correctly, further development question should be handled in Slack. How can I get access there? I don't find a button to register, only to log in.

---

<div class="post-metadata">

**Author:** ![Matthew\_White](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/matthew_white/32/1654_2.png) [@Matthew\_White](https://forum.getodk.org/u/Matthew_White)\
**Post date:** [February 1, 2021, 2:40pm UTC](https://forum.getodk.org/t/extend-api-to-retrieve-plain-json/32204/8 "2021-02-01T14:40:28Z")

</div>

Awesome! You can sign up for the Slack at [https://slack.getodk.org/](https://slack.getodk.org/) (I'll update the link in the contributing guide). You can find us in the #central-code channel there!

---

<div class="post-metadata">

**Author:** ![mathieubossaert](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/mathieubossaert/32/6131_2.png) [@mathieubossaert](https://forum.getodk.org/u/mathieubossaert)\
**Post date:** [April 20, 2021, 8:53am UTC](https://forum.getodk.org/t/extend-api-to-retrieve-plain-json/32204/9 "2021-04-20T08:53:57Z")

</div>

Hi @mattelacchiato and @Matthew_White,

Will it be possible to filter on submission Date when $expand will be use ?

---

<div class="post-metadata">

**Author:** ![mattelacchiato](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/mattelacchiato/32/14421_2.png) [@mattelacchiato](https://forum.getodk.org/u/mattelacchiato)\
**Post date:** [April 20, 2021, 11:01am UTC](https://forum.getodk.org/t/extend-api-to-retrieve-plain-json/32204/10 "2021-04-20T11:01:42Z")

</div>

Yes, of course. We are using both functionality together. Do you have any indication why this shouldn't work?

---

<div class="post-metadata">

**Author:** ![mathieubossaert](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/mathieubossaert/32/6131_2.png) [@mathieubossaert](https://forum.getodk.org/u/mathieubossaert)\
**Post date:** [April 20, 2021, 12:09pm UTC](https://forum.getodk.org/t/extend-api-to-retrieve-plain-json/32204/11 "2021-04-20T12:09:27Z")

</div>

Great. No indication except the filter on SubmissionDate only works on Submissions table.  
It will help a lot to get data from nested table without downloading all of it.

---

<div class="post-metadata">

**Author:** ![Matthew\_White](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/matthew_white/32/1654_2.png) [@Matthew\_White](https://forum.getodk.org/u/Matthew_White)\
**Post date:** [May 19, 2021, 6:37pm UTC](https://forum.getodk.org/t/extend-api-to-retrieve-plain-json/32204/12 "2021-05-19T18:37:09Z")

</div>

ODK Central v1.2 has been [released](https://forum.getodk.org/t/odk-central-v1-2/33583), which means that `$expand=*` is now available for use. Thanks, @mattelacchiato, for contributing this feature!

---

<div class="post-metadata">

**Author:** ![mathieubossaert](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/mathieubossaert/32/6131_2.png) [@mathieubossaert](https://forum.getodk.org/u/mathieubossaert)\
**Post date:** [May 19, 2021, 7:40pm UTC](https://forum.getodk.org/t/extend-api-to-retrieve-plain-json/32204/13 "2021-05-19T19:40:37Z")

</div>

We will upgrade as soon as possible 😉  
Thanks to all the team for the work on that promising release.
