Pawan
Pawan

Reputation: 32321

How to add a Key value to a JSON Array

I have got this JSON valid JSONArray

[
    {
        "RestaurantName": "OhrisHome",
        "Locality": "Near Office"
    },
    {
        "RestaurantName": "SwagtahtHome",
        "Locality": "Near Home"
    }
]

I need to identify this Array with some name

So i am trying to add a Key to this JSON Array as shown

{
  "Type" : "Home"
    [
        {
            "RestaurantName": "OhrisHome",
            "Locality": "Near Office"
        },
        {
            "RestaurantName": "SwagtahtHome",
            "Locality": "Near Home"
        }
    ]
}

Upvotes: 1

Views: 36

Answers (1)

Travis J
Travis J

Reputation: 82287

In the object, they key will be the name of the array, and the values will be the array itself. Just change "ArrayName" to something more applicable.

{
 "Type" : "Home",
 "ArrayName" : 
  [
    {
        "RestaurantName": "OhrisHome",
        "Locality": "Near Office"
    },
    {
        "RestaurantName": "SwagtahtHome",
        "Locality": "Near Home"
    }
  ]
}

Upvotes: 1

Related Questions