roschulze roschulze - 8 months ago 49
Javascript Question

JSON.stringify set root element

I want to convert my object into a JSON String where the root element should be the name of my object.

var data = {
name: 'qwertz',
age: 23,
skills: [
'html', 'css'

var json = JSON.stringify(data);

The output is:


But I want this:


Can someone give me a hint how to reach this? Thanks you :)

Answer Source

As simple as that:

var json = JSON.stringify({ data: data });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download