# JSON decode unknown number of fields

**URL:** <https://discourse.elm-lang.org/t/json-decode-unknown-number-of-fields/6283>\
**Category:** Learn\
**Created:** [September 17, 2020, 4:18pm UTC](https://discourse.elm-lang.org/t/json-decode-unknown-number-of-fields/6283 "2020-09-17T16:18:33Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![iwtilma](https://avatars.discourse-cdn.com/v4/letter/i/f0a364/32.png) [@iwtilma](https://discourse.elm-lang.org/u/iwtilma)\
**Post date:** [September 17, 2020, 4:18pm UTC](https://discourse.elm-lang.org/t/json-decode-unknown-number-of-fields/6283/1 "2020-09-17T16:18:33Z")

</div>

I want to decode a JSON object that looks like this:

```
{ 
  "boxes" : {
    "1" : { 
      "items" : {
        "1" : "pencil",
        "2" : "ball"
      },
    },
    "2" : { 
      "items" : {
        "1" : "teapot",
        "2" : "spoon",
        "3" : "towel"
      }
    }
  }
}

```

I have no control over the JSON format. I get it from an external server.  
My problem while decoding is that I don’t know how many boxes the JSON contains nor how many items each box contains.  
I would like to decode it into a List of boxes that contains a List of items. How should I approach this?

Thanks in advance!

\*\*Edit: \*\* I don’t need the numbers of the boxes and the items.

---

_[View the full topic](https://discourse.elm-lang.org/t/json-decode-unknown-number-of-fields/6283)._
