koajs / bodyparser

Koa body parsing middleware

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failed to decode nested json object

gmarcz opened this issue · comments

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"
            }
          }
        ]
      }
    ]
  }