Search code examples
c#arrays.net-corejson.net

How to make json to json object in c#?


I have a json wants to add square brackets on it (means wants to convert it to json object array) here is my json in response,

    {
  "exampleJson": {
    "test": [
      {
        "xf": "G",
        "sas": "24",
        "ras": 5,
        "asd": 4000,
        "rer": 200,
        "asda": 0
      },
    ],
  }
}  

Now i want this json to as below (Just square brackets before and to the end of the json)

    [{
  "exampleJson": {
    "test": [
      {
        "xf": "G",
        "sas": "24",
        "ras": 5,
        "asd": 4000,
        "rer": 200,
        "asda": 0
      },
    ],
  }
}]

Apart from concatenation is there any way to achieve this ? And this is a JObject which i have created.


Solution

  • The surrounding [] indicates an array is being returned rather than an object, so you need to make your outer container be a JArray:

    var returnedArray = new JArray(jObject);