I have a use case where I need to parse and stringify an object containing arrays of strings. These arrays may include strings that contain commas (","
) as part of their value. For example:
Example 1:
{
"prop": ["val1,val2", "val3"]
}
Example 2:
{
"prop": ["val1,val2"]
}
const stringified = queryString.stringify(a, {
arrayFormat: "comma",
});
const parsed = queryString.parse(stringified, {
arrayFormat: "comma",
});
console.log({ parsed, stringified });
The output of the above code varies depending on the version of query-string
used.
For Example 1, the output does not split "val1,val2"
:
{
"parsed": {
"prop": ["val1,val2", "val3"]
},
"stringified": "prop=val1%2Cval2,val3"
}
For Example 2, the output also does not split "val1,val2"
:
{
"parsed": {
"prop": "val1,val2"
},
"stringified": "prop=val1%2Cval2"
}
For Example 1, the output does not split "val1,val2"
:
{
"parsed": {
"prop": ["val1,val2", "val3"]
},
"stringified": "prop=val1%2Cval2,val3"
}
For Example 2, the output splits "val1,val2"
:
{
"parsed": {
"prop": ["val1", "val2"]
},
"stringified": "prop=val1%2Cval2"
}
For Example 1, the output does not split "val1,val2"
:
{
"parsed": {
"prop": ["val1,val2", "val3"]
},
"stringified": "prop=val1%2Cval2,val3"
}
For Example 2, the output splits "val1,val2"
:
{
"parsed": {
"prop": ["val1", "val2"]
},
"stringified": "prop=val1%2Cval2"
}
Version 6.12.1
works best for my use case. However, I want to understand:
arrayFormat: "comma"
and cannot switch to another format, how should I handle this issue?codesandbox: https://codesandbox.io/p/sandbox/query-string-forked-rwvl3y?file=%2Fsrc%2Findex.js
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too