Skip to content Skip to sidebar Skip to footer

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'

Solution 1:

As simple as that:

var json = JSON.stringify({ data: data });

Solution 2:

Try this

JSON.stringify({'data':data})

Post a Comment for "Json.stringify Set Root Element"