Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert comma separated Query param into KeyValue Pair json object using javascript

I have this Query param that I already converted into JSON.

{"Id":"ZX0123455555,ZX0123455555,ZX0123455545"}

And I want it to become looks like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
"Id": "ZX0123455555",
"Id": "ZX0123455555",
"Id": "ZX0123455545"
}

Just to simplify my JSon schema validation. Thanks

>Solution :

you can’t have an object with the same keys and multiply values but you can have this array:

const myObject = {"Id":"ZX0123455555,ZX0123455555,ZX0123455545"};

const  myArray = myObject.Id.split(',')
const newArray = myArray.map((e)=>{return {Id:e}})

console.log(newArray)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading