I am trying to convert a javascript object into json using JSON.stringify() method. My problem is that when it stingify the object , it only stingify the object's key and values.It does not include the object name.
I want the output like {"Color" : "{"Name":"background","Type":"Color","Value":"Red"}"} but the output comes is {"Name":"background","Type":"Color","Value":"Red"}.
Here is Demo .
I know that json works like this but i want the way to acheive this. Thanks in advance !
The object doesn't know its own name, so you need to explicitly name it in the JSON:
JSON.stringify({'Color': color});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With