How can I parse the given string in C#?
I want to extract the following values - username & ref_id
{
"User":{
"username":"Vinayaka",
"email":"Vinayaka#mindsol.in",
"ref_id":"43523543",
"state_code":"UP",
"active_status":"1",
"user_type":"Admin",
"last_active":"2018-09-22 13:50:23"
}
}
Here's four different ways of parsing your JSON using Newtonsoft.JSON which is one of the most common C# libraries to use for parsing JSON.
Example 1
Deserialization to our own class structure:
Usage:
Root output = JsonConvert.DeserializeObject<Root>(json);
var refId = output.SomeUser.ReferenceId;
Class structure:
/// <summary>
/// Class representing the JSON
/// </summary>
public class Root
{
[JsonProperty("User")]
public User SomeUser { get; set; }
public class User
{
[JsonProperty("username")]
public string UserName { get; set; }
[JsonProperty("email")]
public string EMail { get; set; }
[JsonProperty("ref_id")]
public string ReferenceId { get; set; }
// etc.
}
}
Example 2
Using dynamic types:
dynamic rootObject = JObject.Parse(json);
dynamic user = rootObject.User;
var refId = user.ref_id;
var username = user.username;
Example 3
Token/string property names and generic to extract value:
JObject root = JObject.Parse(json);
var refId = root["User"]["ref_id"].Value<string>();
var username = root["User"]["username"].Value<string>();
Example 4
Using select tokens:
var rootObject = JObject.Parse(json);
var refId = rootObject.SelectToken("User.ref_id");
var username = rootObject.SelectToken("User.username");
You can use System.Web.Script.Serialization.JavaScriptSerializer to parse string to JSON dynamic Object
Here is an example,
var jsonStr = #"{
""User"":{
""username"":""Vinayaka"",
""email"":""Vinayaka#mindsol.in"",
""ref_id"":""43523543"",
""state_code"":""UP"",
""active_status"":""1"",
""user_type"":""Admin"",
""last_active"":""2018-09-22 13:50:23""
}
}";
var json = new JavaScriptSerializer();
var data = json.Deserialize<dynamic>(jsonStr);
foreach(KeyValuePair<string,object> p in data["User"])
{
Console.WriteLine(string.Format("{0} : {1}", p.Key, p.Value));
}
You can also check for Newtonsoft.JSON
Alternatively, you may have a look at this "Quick and Dirty" approach.
Two simple methods:
static string QuickAndDirtyJsonLookupText(string json, string key) =>
QuickAndDirtyJsonFind(json, key).Split('"')[1];
static string QuickAndDirtyJsonFind(string json, string key) {
int keyIndex = json.IndexOf($"\"{key}\":");
if (keyIndex < 0)
throw new KeyNotFoundException($"Key \"{key}\" not found in '{json}'.");
return json.Substring(keyIndex + 3 + key.Length).TrimStart();
}
Lets you lookup what you need, for example:
const string json =
"{"+
" \"User\":{" +
" \"username\":\"Vinayaka\"," +
" \"email\":\"Vinayaka#mindsol.in\"," +
" \"ref_id\":\"43523543\"," +
" \"state_code\":\"UP\"," +
" \"active_status\":\"1\"," +
" \"user_type\":\"Admin\"," +
" \"last_active\":\"2018-09-22 13:50:23\"" +
" }" +
"}";
Assert.AreEqual("Vinayaka", QuickAndDirtyJsonLookupText(json, "username"));
Assert.AreEqual("43523543", QuickAndDirtyJsonLookupText(json, "ref_id"));
Of course, this is indeed "quick and dirty" and only works, if you know the structure of your json ahead of time, and if you know that the text values do not contain quotes - which is often the case. You can also easily add your own QuickAndDirtyJsonLookupInt, for instance.
If you want a more structured approach with full source code, check out my lightweight parser and generator on https://github.com/Dbquity/Json.
Related
I am using System.Linq.Dynamic.Core v1.0.8.18
I am abbreviating the object I have--I have eliminated the JSON tags for serialization/deserialization as well as the constructor. Below is the abbreviated class for a line item on an order. Please note that this object is deserialized from JSON, and the purpose of the "other" dictionary is to capture any name/value pair that is not explicitly defined in the object (which works exactly as it should in testing and production):
public partial class OrderRequestItem
{
public string line_number { get; set; }
public decimal quantity { get; set; }
public string supplier_id { get; set; }
public string supplier_aux_id { get; set; }
public decimal unitprice { get; set; }
public string description { get; set; }
public string uom { get; set; }
public IDictionary<string, object> other;
public decimal extension
{
get
{
return unitprice * quantity;
}
}
public bool validated { get; set; }
public bool rejected { get; set; }
}
I am attempting to "split" an order using the following code based on a JSON config file entry that specifies which fields to split the order on (parameter 2):
private List<OrderRequest> SplitOrder(OrderRequest originalOrder, string[] orderSplitLineItemFields = null)
{
var retval = new List<OrderRequest>();
if (null == orderSplitLineItemFields || originalOrder.items.Count < 2) //Can't return more than one order if we don't have fields to split by, and we don't have at least 2 line items.
{
retval.Add(originalOrder);
}
else
{
var bareOrderHeader = (OrderRequest)originalOrder.DeepClone();
bareOrderHeader.items.Clear();
var firstLineItem = originalOrder.items[0];
var validOrderSplitLineItemFields = new List<string>();
var dynamicQueryBase = new List<string>();
int validFieldCount = 0;
foreach (var field in orderSplitLineItemFields)
{
if (firstLineItem.HasProperty(field))
{
validOrderSplitLineItemFields.Add(field);
dynamicQueryBase.Add(field + " = #" + validFieldCount++);
}
else if (null != firstLineItem.other[field])
{
validOrderSplitLineItemFields.Add("other[\"" + field + "\"]");
dynamicQueryBase.Add("other[\"" + field + "\"]" + " = #" + validFieldCount++);
}
}
if(validOrderSplitLineItemFields.Count<1) //Can't return more than one order if we don't have valid fields to split by.
{
retval.Add(originalOrder);
}
else //We have valid fields to split the order, so we might be able to return more than one order.
{
string distinctFields = String.Join(",", validOrderSplitLineItemFields);
var distinctFieldValues = originalOrder.items.AsQueryable().Select(distinctFields).Distinct();
var dynamicWhere = string.Join(" and ", dynamicQueryBase);
var originalLineItems = originalOrder.items.AsQueryable();
foreach (var distinctResult in distinctFieldValues)
{
var newOrderSplit = (OrderRequest)bareOrderHeader.DeepClone();
var results = originalLineItems.Where(dynamicWhere, distinctResult);
foreach (var lineitem in results)
{
newOrderSplit.items.Add(lineitem);
}
retval.Add(newOrderSplit);
}
}
}
return retval;
}
The field that I am attempting to split on is called "requested_delivery_date" which is being properly passed in to the SplitOrder function. Because this is not an actual property of OrderRequestItem, the split code checks (and in fact succeeds) in looking at/finding a dictionary entry in the "other" property and appropriately adds the field to the list of dynamic fields upon which to query--(I do it this way because the specifically defined properties are "required" and I won't be able to predict what additional fields we may be sent on future orders with other buyers).
I have a sample order file that contains 4 line items. The lines 1, 2, 3 all have a defined other["requested_delivery_date"] = 2018-09-29, and line 4 has a other["requested_delivery_date"] = 2018-09-30.
Based on the code, I would expect to return two orders, one with line items 1-3, and another with only line 4. However, what I am actually getting back is two orders, one with only line item #1, and another with only line item #4. It seems as though the line
var results = originalLineItems.Where(dynamicWhere, distinctResult);
only ever returns a single result when I query against the dictionary that is a member of OrderRequestItem.
I have been beating my head against the wall here for the better part of the day and I don't understand why I only get a single result when the debugger is showing me that the original list of items I am querying have more matches. I'm starting to think it is a bug in the current version of System.Linq.Dynamic.Core.
Any help/suggestions appreciated! Keep in mind that I need to use dynamic linq since I will be dealing with new or changed additional fields on the line items all the time--so going back to "regular linq" isn't an option here.
Changed this
dynamicQueryBase.Add("other[\"" + field + "\"]" + " = #" + validFieldCount++);
to this
dynamicQueryBase.Add("other[\"" + field + "\"].ToString()" + " = #" + validFieldCount++);
makes it work as expected.
I can't test right now, maybe the default return for "where" is only a single item.
Try
var results = originalLineItems.Where(dynamicWhere, distinctResult).ToList();
And check if it's working fine.
I have the following working controller method, which returns the JSON in a simple text format.
[HttpPost]
public IActionResult DecodeBarcode(string productCodeScheme, string productCode, string serialNumber, string batch, string expirationDate, int commandStatusCode) {
string TextAreaResult = string.Empty;
try {
TextAreaResult = string.Format("{0} {1} {2}", request.getHttpInformation(), request.getHttpWarning(), request.getHttpResponseCode());
} catch (Exception exc) {
TextAreaResult = "Exception: " + exc.Message;
}
return Json(TextAreaResult);
}
The output after the above method is run looks something like
"The pack is active No warning 200"
whereas
request.getHttpInformation() is The pack is active
request.getHttpWarning() is No warning
request.getHttpResponseCode() is 200
Now, I am trying to split the response into 3 different key-value pairs so that my response will look like
{
httpInformation: "The pack is active",
httpWarning: "No Warning",
httpResponseCode: "200"
}
How do I pass the additional params in return Json(TextAreaResult) call?
If I do like the following it won't work
[HttpPost]
public IActionResult DecodeBarcode(string productCodeScheme, string productCode, string serialNumber, string batch, string expirationDate, int commandStatusCode) {
string TextAreaResult = string.Empty;
string TextAreaResultHttpInformation = string.Empty;
string TextAreaResultHttpWarning = string.Empty;
string TextAreaResultHttpResponseCode = string.Empty;
try {
TextAreaResultHttpInformation = string.Format("{0}}", request.getHttpInformation());
TextAreaResultHttpWarning = string.Format("{1}}", request.getHttpWarning());
TextAreaResultHttpResponseCode = string.Format("{2}}", request.getHttpResponseCode());
} catch (Exception exc) {
TextAreaResult = "Exception: " + exc.Message;
}
return Json(TextAreaResultHttpInformation, TextAreaResultHttpInformation, TextAreaResultHttpResponseCode);
}
How do I construct the key-value pairs and return as JSON? Perhaps, Json method is not the right choice over here, but being new to C#, I am not aware of any other c# inbuilt methods for constructing JSON
Assuming you actually want to consume the response as JSON, you could achieve this by doing
return Json(new
{
HttpInformation = TextAreaResultHttpInformation,
HttpWarning = TextAreaResultHttpWarning,
StatusCode = TextAreaResultHttpResponseCode
});
You can make wrapper class for these properties and return it.
public class BarcodeResultDto
{
[JsonProperty("httpInformation")]
public string HttpInformation { get; set; }
[JsonProperty("httpWarning")]
public string HttpWarning { get; set; }
[JsonProperty("httpResponseCode")]
public int GetHttpResponseCode { get; set; }
}
public IActionResult DecodeBarcode(string productCodeScheme, string productCode, string serialNumber,
string batch, string expirationDate, int commandStatusCode)
{
var barcodeResult = new BarcodeResultDto
{
GetHttpResponseCode = 200,
HttpInformation = "The pack is active",
HttpWarning = "No Warning"
};
// your code here
return Ok(barcodeResult);
}
Or you can change retuned value from IActionResult to JsonResult
If you want a different approach then you can use JsonSerializer in the following way :
// Creating BlogSites object
BlogSites bsObj = new BlogSites()
{
Name = "test-name",
Description = "test-description"
};
// Serializing object to json data
JavaScriptSerializer js = new JavaScriptSerializer();
string jsonData = js.Serialize(bsObj); // {"Name":"test-name","Description":"test-description"}
You will just need to create a class and store value in its objects then serialize it. If you have a list then you can use List of that class and then serialize.
string a;
string b;
string jSonContent = #"{""fields"":{""summary"":""summary"" , ""description"": ""modified.""}}";
I want a instead of summary and b instead of modified. It works if I replace summary but gives errors if I replace both.
The edited code is, string jSonContent = #"{""fields"":{""summary"":"+ "\""+ a+ "\"" +" , ""description"": "+ "\""+ b+ "\"" +"}}"; It's not giving any error, summary field is getting updated, but the description field is not.
Please revert. Thanks!
I highly suggest you to use JSON library, for example Json.Net.
First of all, you'll be able to work with strongly typed objects, in addition you will avoid typos and similar bugs since the serializer will do the serialization for you.
public void Test()
{
string a = ""; //content of 'a' variable
string b = ""; //content of 'b' variable
var obj = new RootObject();
obj.Fields = new Fields();
obj.Fields.Summary = a;
obj.Fields.Description = b;
var jsonOutput = Newtonsoft.Json.JsonSerializer.Serialize(obj, typeof(RootObject));
}
public class Fields
{
[JsonProperty("summary")]
public string Summary { get; set; }
[JsonProperty("description")]
public string Description { get; set; }
}
public class RootObject
{
[JsonProperty("fields")]
public Fields Fields { get; set; }
}
Note: If you don't want to create unnecessary types, you can work directly with JObject, this is one of possible uses:
var jobj = Newtonsoft.Json.Linq.JObject.FromObject(new {
fields = new {
summary = a,
description = b
}
});
var jsonOutput = jobj.ToString();
string a = "a";
string b = "b";
string jSonContent = (#"{""fields"":{""summary"":""summary"" , ""description"": ""modified.""}}").Replace(#":""summary""", a).Replace("modified.", b);
You can use string.Format or string.concate Method
string jSonContent = string.Concat("{\"fields\":{\"summary\":","\"",a,"\" , \"description\": \"",b,"\"}}");
Use string fromat $""
String format allow you to replace values from your variables into a string. E.g.
string name = "Bruno";
string result = $"My name is {name}";
Console.WriteLine(result);
The output will be
My name is Bruno
In your case you just have to escape the json brackets with a double bracket {{
string a = "this is a sumary";
string b = "this is a description";
string jSonContent = $"{{\"fields\":{{\"summary\":\"{a}\" , \"description\": \"{b}\"}}}}";
Console.WriteLine(jSonContent);
the output is
{"fields":{"summary":"this is a sumary" , "description": "this is a description"}}
However I strongly advise to not build your json strings manually, use Json.NET or any other NuGet Packages.
I am trying to convert a list to a json string. The json is generating fine, but when I try to generate an array within the JSON it won't format properly.
My list is generated
List<string> invoicesList = new List<string>();
foreach (var invoice in theInvoices)
{
invoicesList.Add(invoice.InvoiceNumber);
invoicesList.Add(String.Format("{0:c}", invoice.GrandTotal));
invoicesList.Add(FieldTranslation.ToShortDate(invoice.Date.ToString()));
}
Then I add it to the JSON
var info = new MobileAPIHelper.ClientPayrollInfo
{
GrossWages = String.Format("{0:c}", GrossWages),
InvoiceTotal = String.Format("{0:c}", invoiceTotal),
InvoiceDate = FieldTranslation.ToShortDate(invoiceDate.ToString()),
InvoiceList = invoicesList.ToArray()
};
The output ends up just being a long JSON string with everything from the list
"InvoiceList":["SALES000000000006","$9,300.00","4/11/2016","SALES000000000008","$4,650.00","12/22/2015"]
What I can't figure out is how to get the list / json to format that invoicelist like so:
"InvoiceList":[{
"SALES000000000006","$9,300.00","4/11/2016"
},{
"SALES000000000008","$4,650.00","12/22/2015"
}]
invoicesList is not a list of an object that contains those values, it's a list of strings. You need to make a class that acts as a container for
invoice.InvoiceNumber;
String.Format("{0:c}", invoice.GrandTotal);
invoice.Date.ToString());
these fields. Make invoicesList a list of that class, then parse it to json. You're adding raw strings.
If you make those string as object.
public class Invoice{
public string InvoiceNumber{get;set;}
public string GrandTotal{get;set;}
public string Date{get;set;}
}
List<Invoice> invoicesList = new List<Invoice>();
foreach (var invoice in theInvoices)
{
invoicesList.Add(new Invoice(){InvoiceNumber=invoice.InvoiceNumber,
GrandTotal= invoice.GrandTotal,
Date=FieldTranslation.ToShortDate(invoice.Date.ToString())});
}
Then there is a package called NewtonSoftJson which allows you to convert from Collection.
Go to package manager console (Click on view menu in visual studio-> Other windows -> Package Manager console)
Install-Package Newtonsoft.Json
C# code
var invoiceListString=JsonConvert.SerializeObject(invoicesList);
I will recommend to use NewtonSoft.Json.
public class Invoice
{
public string InvoiceNumber { get; set; }
public DateTime InvoiceDate { get; set; }
public string InvoiceTotal { get; set; }
}
public void PrintJson()
{
List<Invoice> InvoiceList = new List<Invoice>();
var outputObject = new { InvoiceList };
InvoiceList.Add(new Invoice { InvoiceNumber = "SALES0000001", InvoiceDate = DateTime.UtcNow, InvoiceTotal = String.Format("{0:c}", "90000") });
InvoiceList.Add(new Invoice { InvoiceNumber = "SALES0000002", InvoiceDate = DateTime.UtcNow, InvoiceTotal = String.Format("{0:c}", "60000") });
var output1 = JsonConvert.SerializeObject(outputObject);
var output2 = JsonConvert.SerializeObject(InvoiceList);
}
Output1
{"InvoiceList":[{"InvoiceNumber":"SALES0000001","InvoiceDate":"2017-02-22T16:46:31.6933956Z","InvoiceTotal":"90000"},{"InvoiceNumber":"SALES0000002","InvoiceDate":"2017-02-22T16:46:31.6933956Z","InvoiceTotal":"60000"}]}
Output2
[{"InvoiceNumber":"SALES0000001","InvoiceDate":"2017-02-22T16:46:31.6933956Z","InvoiceTotal":"90000"},{"InvoiceNumber":"SALES0000002","InvoiceDate":"2017-02-22T16:46:31.6933956Z","InvoiceTotal":"60000"}]
Please notice the Json in your question is not valid.
As pointed by Dispersia, your list is one big string list and, therefore, the json serializer behaves as requested -- turns this big string list into a big json string array.
I haven't got VS at hand to test the code below but try turning your invoice list into something like:
List<Tuple<String, String, String>> invoiceList = new List<>();
and then add tuples accordingly:
foreach (var invoice in theInvoices)
{
Tuple<String, String, String> t = new Tuple<>(
invoice.InvoiceNumber,
String.Format("{0:c}", invoice.GrandTotal),
FieldTranslation.ToShortDate(invoice.Date.ToString()));
invoicesList.Add(t);
}
Would that help?
I have a JsonString:
"baseAbilities":"[{"baseId":1,"name":"Focused Elemental Strike"}]"
I want to make it:
"baseAbilities":[{"baseId":1,"name":"Focused Elemental Strike"}]
So the it is easy for JSON utility to deserialise it. Any suggestions
EDIT:
This is basically a json object in the following Json String:
{"data”: [{"id":9,"name":"Sam5","baseAbilities":"[{\"baseId\":1,\"name\":\"Focused Elemental Strike\"},{\"baseId\":9,\"name\":\"Cleanse\"}]"]}
The backend developer saved JSON in a column baseAbilities as a string. Now I don't have the access to Back end APIs. So i need to convert this string baseAbilities to JSON so that I can access objects inside it.
Now I use these classes to decode JSON:
[System.Serializable]
class GetBAResult
{
public List<bounceAbilityData> data;
}
[System.Serializable]
class bounceAbilityData
{
public int id;
public string name;
public string baseAbilities;
}
And this is how I decode JSON:
GetBAResult P = JsonUtility.FromJson<GetBAResult>(w.text);
for (int i = 0; i < P.data.Count; i++)
{
Debug.Log(P.data[i].name);
GameObject layoutGroupNameButton = (GameObject)Instantiate(prefabBAButton);
layoutGroupNameButton.transform.SetParent(ParentPanel, false);
layoutGroupNameButton.GetComponentInChildren<Text>().text = P.data[i].name;
layoutGroupNameButton.GetComponent<BounceAbilityButton>().id = P.data[i].id;
layoutGroupNameButton.GetComponent<BounceAbilityButton>().name = P.data[i].name;
Debug.Log(P.data[i].baseAbilities);
}
I need to get things inside baseAbilities such as "baseID" and "name"
Have you tried this?
JObject json = JObject.Parse(str);
documentation
With a class set of
[System.Serializable]
class GetBAResult
{
public List<bounceAbilityData> data;
}
[System.Serializable]
class bounceAbilityData
{
public int id;
public string name;
public List<BaseAbilities> baseAbilities;
}
[System.Serializable]
class BaseAbilities
{
public int baseId;
public string name;
}
You can then use the following to Deserialize your JSON to an instance of GetBAResult
string json = "{\"data\":[{\"id\":9,\"name\":\"Sam5\",\"baseAbilities\":[{\"baseId\":1,\"name\":\"Focused Elemental Strike\"},{\"baseId\":9,\"name\":\"Cleanse\"}]}]}";
GetBAResult myObject = JsonUtility.FromJson<GetBAResult>(json);
BaseAbilities abilities = myObject.data[0].baseAbilities[0];
You can read more about JSON Deserialization here on the Unity Documentation
https://docs.unity3d.com/Manual/JSONSerialization.html
The original questions says that you want to change:
"baseAbilities":"[{"baseId":1,"name":"Focused Elemental Strike"}]"
to
"baseAbilities":[{"baseId":1,"name":"Focused Elemental Strike"}]
Basically, you want to remove the " before the [{" then remove the final " at the end of the json string. The problem is that even after you do this, "baseAbilities":[{"baseId":1,"name":"Focused Elemental Strike"}] cannot be serialized to json.
You need to add { in front of it and } at the end of it.
The final string after adding { in front of it and } at the end is:
{"baseAbilities":[{"baseId":1,"name":"Focused Elemental Strike"}]}
The fixJson function below fixes those problems and this is how to use it:
[System.Serializable]
public class BaseAbility
{
public int id;
public string name;
}
[System.Serializable]
public class GetBAResult
{
public List<BaseAbility> baseAbilities;
}
void Start()
{
// StartCoroutine(RespawnPlayer());
string fixedJson = fixJson(w.text);
//string fixedJson = fixJson("\"baseAbilities\":\"[{\"id\":1,\"name\":\"Focused Elemental Strike\"}]\"");
Debug.Log("Fixed Json: " + fixedJson);
GetBAResult P = JsonUtility.FromJson<GetBAResult>(fixedJson);
Debug.Log("Count Json: " + P.baseAbilities.Count);
for (int i = 0; i < P.baseAbilities.Count; i++)
{
Debug.Log("Name: " + P.baseAbilities[i].name);
Debug.Log("Base ID: " + P.baseAbilities[i].id);
}
}
string fixJson(string jsonToFix)
{
//First srting with `"` that will be removed
const string firstString = "\"baseAbilities\":\"";
//Last string with `"` that will be removed
const string lastString = "\"";
//String that will be used to fix the "baseAbilities":"[ with the `"`
const string fixedFirstString = "\"baseAbilities\":";
//Get the first Index of firstString
int firstIndex = jsonToFix.IndexOf(firstString);
//Remove First Index of `firstString`
jsonToFix = jsonToFix.Remove(firstIndex, firstString.Length);
int lastIndex = jsonToFix.LastIndexOf(lastString);
//Remove everything from Last `lastString` to the end
jsonToFix = jsonToFix.Remove(lastIndex);
//Append the correct/fixed string without `"` to the beginning of the json data
jsonToFix = fixedFirstString + jsonToFix;
//Add `{` to the begging and `}` to the end of the json data
jsonToFix = "{" + jsonToFix + "}";
return jsonToFix;
}
Let's say you have a class like this:
using System;
using System.Collections.Generic;
using UnityEngine;
public class JsonTest : MonoBehaviour
{
[Serializable]
public class Ability
{
public int baseId;
public string name;
public Ability(int _baseId, string _name)
{
baseId = _baseId;
name = _name;
}
}
public class Abilities
{
public List<Ability> baseAbilities;
public Abilities(List<Ability> _baseAbilities)
{
baseAbilities = _baseAbilities;
}
}
void Start()
{
List<Ability> list = new List<Ability>();
list.Add(new Ability(1, "Focused Elemental Strike"));
list.Add(new Ability(2, "Another ability"));
Abilities baseAbilities = new Abilities(list);
string serializedAbilites = JsonUtility.ToJson(baseAbilities);
Debug.Log(serializedAbilites);
Abilities deserializedAbilites = JsonUtility.FromJson<Abilities>(serializedAbilites);
}
}
You have an Ability class marked as Serializable containing and id and a name.
You have another class Abilities used as a wrapper for a list of abilities.
You can then serialize a list of abilities using JsonUtility.ToJson(). Which will give you the following string:
{
"baseAbilities": [
{
"baseId": 1,
"name": "Focused Elemental Strike"
},
{
"baseId": 2,
"name": "Another ability"
}
]
}
And of course you can deserialize it using JsonUtility.FromJson().
Is this what your looking for ?