koajs / bodyparser

Koa body parsing middleware
MIT License
1.3k stars 116 forks source link

Failed to decode nested json object #113

Closed gmarcz closed 5 years ago

gmarcz commented 5 years ago

I don't know that this is somekind of limitation or a bug, but I have issue with decoding a nested json object.

The posted form data looks like this:

quotaPlan[quotaGroups][0][quotaCells][0][perc]: 40
quotaPlan[quotaGroups][0][quotaCells][0][quotaNodes][0][attributeId]: 11
quotaPlan[quotaGroups][0][quotaCells][0][quotaNodes][0][options][]: 1
quotaPlan[quotaGroups][0][quotaCells][0][quotaNodes][1][attributeId]: 13
quotaPlan[quotaGroups][0][quotaCells][0][quotaNodes][1][options][]: 30-50
quotaPlan[quotaGroups][0][quotaCells][1][perc]: 60
quotaPlan[quotaGroups][0][quotaCells][1][quotaNodes][0][attributeId]: 11
quotaPlan[quotaGroups][0][quotaCells][1][quotaNodes][0][options][]: 2
quotaPlan[quotaGroups][0][quotaCells][1][quotaNodes][1][attributeId]: 13
quotaPlan[quotaGroups][0][quotaCells][1][quotaNodes][1][options][]: 30-50

And the result (ctx.request.body) on the server side:

"quotaPlan": {
    "quotaGroups": [
      {
        "name": "age 30-50",
        "quotaCells": [
          {
            "perc": "40",
            "quotaNodes": {
              "[0][attributeId]": "11",
              "[0][options][]": "1",
              "[1][attributeId]": "13",
              "[1][options][]": "30-50"
            }
          },
          {
            "perc": "60",
            "quotaNodes": {
              "[0][attributeId]": "11",
              "[0][options][]": "2",
              "[1][attributeId]": "13",
              "[1][options][]": "30-50"
            }
          }
        ]
      }
    ]
  }