Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add quotation marks to JSON Object attributes

How do I add quotation marks to a JSON Object attributes for example like this:

{name:"User 01"}

so it should look like that afterward:

{"name":"User 01"}

both of them are strings

like image 355
Livio Brunner Avatar asked Jun 09 '26 13:06

Livio Brunner


1 Answers

Assuming the first example is a Javascript object, you could convert it into a JSON string using JSON.stringify:

JSON.stringify({name:"User 01"});

outputs: "{"name":"User 01"}"

Assuming String

If the first example is a string, I think you would have to parse through it with methods like split.

like image 71
bozdoz Avatar answered Jun 11 '26 06:06

bozdoz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!