I tried to create json string according to syntax from wikipedia. I created json string with the following code:
var data = [];
data.push(
{
"firstName": "John",
"lastName": "Smith",
"isAlive": true,
"age": 27,
});
var addressdata = [];
addressdata.push(
{
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"
});
data.push(
{
"address" : addressdata
}
);
The string is correct json string. However, the json structure contains some unnecessary nesting, as shown in the Figures 1 and 2 below. More precisely, there are surplus braces for address block, and the string is also enclosured with brackets instead of braces. So, what am I doing wrong? How can I avoid this unnecessary nesting and get structure as shown in Fig. 3?
Fig. 1
Fig. 2
Fig. 3
The string is generated with jsonData : data,
in Ajax request.
question from:
https://stackoverflow.com/questions/65835747/how-to-avoid-extra-nesting-in-json-string 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…