You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using parse() on a node server (vanilla node http server, not express) to parse a long, not known in advance, querrystring to JSON. I also need to convert the values to the correct type. I understand that qs doesn't do type coercion by design. Here is my issue
If i just use parse without options every value is a string but my nested values are correctly displayed. But if I use a custom decoder to convert the types :
const data = qs.parse(body, {
decoder(value) {
if (/^(\d+|\d*\.\d+)$/.test(value)) {
return parseFloat(value);
}
const keywords: Record<string, any> = {
true: true,
false: false,
null: null,
undefined: undefined,
};
if (value in keywords) {
return keywords[value];
}
return value;
},
});
then I lost nesting. How do I manage to keep the nesting along type coercion ?
The text was updated successfully, but these errors were encountered:
Hello,
I am using parse() on a node server (vanilla node http server, not express) to parse a long, not known in advance, querrystring to JSON. I also need to convert the values to the correct type. I understand that qs doesn't do type coercion by design. Here is my issue
If i just use parse without options every value is a string but my nested values are correctly displayed. But if I use a custom decoder to convert the types :
then I lost nesting. How do I manage to keep the nesting along type coercion ?
The text was updated successfully, but these errors were encountered: