ljharb / qs

A querystring parser with nesting support
BSD 3-Clause "New" or "Revised" License
8.5k stars 729 forks source link

why this object is not parsed correctly? (help wanted!!!) #451

Closed baaraak closed 2 years ago

baaraak commented 2 years ago

Hi, i'm trying to stringify and parse this object but i'm keep getting the wrong result... every this newFiltes[0].filters[0/1].value.value should be array of strings, it's always transforming this array to {0: 'string', 1: 'string'} no matter what i pass to arrayLimit... hope i'm not missing something here. thanks. https://codesandbox.io/s/musing-alex-l8i2h7?file=/src/App.js

Screen Shot 2022-08-21 at 1 48 49
{
  newFilters: [
    {
      id: 0,
      filters: [
        {
          value: {
            value: [1660424400000, 1661115599999],
            operator:
              "eyJuYW1lIjoiX2FuZCIsInR5cGUiOiJtYXRjaCIsImxhYmVsIjoiRHVyaW5nIiwiY29tcG9uZW50cyI6WyJleUp1WVcxbElqb2lYMmQwWlNJc0lteGhZbVZzSWpvaVIzSmxZWFJsY2lCMGFHRnVJR1Z4ZFdGc0luMD0iLCJleUp1WVcxbElqb2lYMngwWlNJc0lteGhZbVZzSWpvaVRHVnpjeUIwYUdGdUlHVnhkV0ZzSW4wPSJdfQ=="
          },
          name: "date",
          type: "date",
          isDefault: true
        },
        {
          value: {
            value: ["60071434"],
            operator: "eyJuYW1lIjoiX2luIiwibGFiZWwiOiJNYXRjaCBhbnkifQ=="
          },
          name: "accounts",
          type: "accounts"
        }
      ],
      conjunction: "and"
    }
  ]
}
ljharb commented 2 years ago

Did you figure it out?

baaraak commented 2 years ago

nope... not relevant for me anymore

ljharb commented 2 years ago

@baaraak ok - that's confusing. Why is it no longer relevant?

ljharb commented 2 years ago

fwiw this is because there isn't currently any sensible way to omit indices, AND have an array of objects. If you stringify with arrayFormat: indices then it should round-trip just fine.

baaraak commented 2 years ago

not relevant because I'm saving the data in a different structure now, so the new structure works fine. I assumed that probably I have a typo somewhere and it's not a bug in qs. BTW, I'm trying to add the arrayFormat: indices, but it's still not working...

const sting = stringify(filters, {arrayFormat: 'indices'});
const parsed = parse(sting, {arrayLimit: 100});
console.log(parsed);

still going to transform the value.value arrays into objects https://codesandbox.io/s/restless-meadow-3zbxi8?file=/src/App.js

ljharb commented 2 years ago

I see what you mean: https://codesandbox.io/s/bitter-cloud-1jc73n?file=/src/App.js it round trips to a string correctly, but not to the initial nested array. This is definitely worth fixing.