API Json response to datatable

Hello guys. I have an API response in json format like this:
{
“valid”:false,
“number”:“829031559,512889”,
“local_format”:“”,
“international_format”:“”,
“country_prefix”:“”,
“country_code”:“”,
“country_name”:“”,
“location”:“”,
“carrier”:“”,
“line_type”:null
}
How can i convert it to Datatable? Been trying with newtonsoft, but was unsucsesful

Hi @Povilas_Jonikas

Deserialize JSON (Output: jsonObject) -> Assign: numberString = jsonObject("number").ToString
Assign: numbers = numberString.Split(","c)

Build Data Table (Output: dataTable)
   Add  Column Name: ("Number", "Valid", "Local Format", "International Format")

For Each (item in numbers)
   Assign: dataRow = dataTable.NewRow()
   dataRow("Number") = item
   dataRow("Valid") = jsonObject("valid").ToString
   dataRow("Local Format") = jsonObject("local_format").ToString
   dataRow("International Format") = jsonObject("international_format").ToString
   Add Data Row (Input: dataRow) to dataTable

Hope it helps!!

Deserialize the JSON with:
grafik
output: myJObject | TypeArgument: JObject

then we can convert this JObject to a DataTable by:

myDataTable =
Newtonsoft.Json.Linq.JArray.FromObject(new JObject(){myJObject}).ToObject(Of DataTable)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.