Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing the stringify result would lead to a different object #472

Closed
exneval opened this issue May 5, 2023 · 1 comment
Closed

Parsing the stringify result would lead to a different object #472

exneval opened this issue May 5, 2023 · 1 comment
Labels

Comments

@exneval
Copy link

exneval commented May 5, 2023

I don't know if this issue kind of duplicate with #471
So I've tried to stringify an object

const obj = {
  $lookup: {
    '*': [
      {
        products: {
          $lookup: {
            '*': ['categories'],
          },
        },
      },
    ],
  },
};

const queryString = qs.stringify(obj, { encodeValuesOnly: true });

console.log(queryString); // $lookup[*][0][products][$lookup][*][0]=categories

Then, using the stringify result to parse back to object again

const queryObject = qs.parse(queryString);

console.log(JSON.stringify(queryObject, null, 2));
// {
//   "$lookup": {
//     "*": [
//       {
//         "products": {
//           "$lookup": {
//             "*": {
//               "[0]": "categories"
//             }
//           }
//         }
//       }
//     ]
//   }
// }

as we can see, the parsed result is not the same as original object
Please kindly check it @ljharb

@ljharb
Copy link
Owner

ljharb commented May 15, 2023

The issue is the depth - qs.parse(queryString, { depth: 50 }); produces the expected object, for example. The default of depth in the docs is 5.

@ljharb ljharb closed this as completed May 15, 2023
@ljharb ljharb added the parse label May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants