Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

json does not include object name during stingify

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 !

like image 439
Sudarshan Avatar asked Jul 31 '26 10:07

Sudarshan


1 Answers

The object doesn't know its own name, so you need to explicitly name it in the JSON:

JSON.stringify({'Color': color});
like image 65
RichieHindle Avatar answered Aug 03 '26 01:08

RichieHindle