question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stringify nested object so output only contains values

See original GitHub issue

I’ve been trying for a while to output a query string from a nested array. I’m using qs.stringify(data, { arrayFormat: 'brackets', indices: false, encode: false}) ) and the output I’m getting is 0[name]=first-name&0[value]=&1[name]=surname&1[value]=&2[name]=email&2[value]=&3[name]=contact-number&3[value]=&4[name]=.

I’d like the output to be first-name=&surname=&email=&contact-number= Is it possible or do I have to do something to the array before I use stringify?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Mouckycommented, Oct 5, 2021

That looks like it’s done it! Thank you so much.

0reactions
ljharbcommented, Oct 5, 2021

ha, sorry, i’m just winging this 😃

Try Object.fromEntries(data.map(x => [x.name, x.value]))

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON.stringify() losing nested properties I know the cause but ...
I know the cause: it's because that the properties in extra object are not enumerable. So far, I have tried: 1.use the spread:...
Read more >
javascript json stringify nested objects - You.com
stringify () doesn't seem to want to stringify nested objects. It was working before so i'm not sure why it's not working now....
Read more >
JSON.stringify() - JavaScript - MDN Web Docs
The JSON.stringify() method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified or ...
Read more >
The trick to making console.log play nice with complex objects
But in Node.js, when you look at the output of a nested object, ... have a nice UI for drilling down, so Node...
Read more >
The Best Way to Deep Copy an Object in JavaScript - Code
JSON.stringify() and JSON.parse(), deep copies nested objects ... As observed in the console output, we have now copied the object from user ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found