Assign: Unexpected JSON token when reading DataTable: StartObject. Path '[0].entry', line 3, position 14


Guys am facing an error while am tryig to save json data respose to a datatable then save it again to an excel file.
this is the error am getting: Unexpected JSON token when reading DataTable: StartObject. Path ‘[0]. entry’, line 3, position 14.

Show us the expression you have in “Value to save” and show us what your JSON looks like.

as above requested, for help the used statement is to share for the review. We would also recommend to share the JSON with us.

when it is about the JArray…toObject(Of DataTable) trick keep in mind that the JSON has to fullfill certain contstraints as well for getting converted into the datatable

expression value : Newtonsoft.Json.JsonConvert.DeserializeObject(of DataTable)(DjArray.ToString)

json response :
TestDjson2.txt (315.4 KB)

this nested structure of the items ( the entry elements) is not matching the constraints that is to meet for a json reflecting a serialized DataTable

@mulamuleli.mudzunga

Yeah, datatables are two dimensional - columns and rows. The JSON has nested objects so you can’t just directly convert it to datatable. What do you want the datatable to look like?

i dont want all the columns only (entry/name) and (entry/id)

Your json file is JArray (that’s why it starts with [), so you have to Parse it as such. Then just loop through it and get the (“entry”)(“name”) and (“entry”)(“id”):

"Name: " + JObject.Parse(currentJToken.ToString)("entry")("name").ToString + "; id: " + JObject.Parse(currentJToken.ToString)("entry")("id").ToString

image

So instead of Log Message just use Add Data Row to add each one to a datatable.

1 Like

Option Essential:

  • Build DataTable, Configure 2 cols: Name, ID - dtReport

  • Deserialize original JSON (the fullone with the list/entries properties) - myJObject

  • For each Acitity | item in myJObject(“list”)(“entries”).Values(Of JObject) (set typeargument when needed to JObject

    • Add Data Row Activity|
      ArrayRow: new Object(){) item.SelectToken("entry.name").Value(Of String), item.SelectToken("entry.id").Value(Of String)}
      DataTable: dtReport

the experimental long oneliner:

grafik

Jarray.FromObject(myJObject("list")("entries").Select(Function (x) new JObject({x("entry").Value(Of JObject).Property("name"),x("entry").Value(Of JObject).Property("id")}))).ToObject(Of DataTable)

Decomposed to:

myEntries | List(Of JObjects) = myJObject("list")("entries").Values(Of JObject).toList
myRowJOs | List(Of JObjects) = myEntries.Select(Function (x) new JObject({x("entry").Value(Of JObject).Property("name"),x("entry").Value(Of JObject).Property("id")}))
myDataTable = JArray.FromObject(myRowJOs).ToObject(Of DataTable)

This gives errors when adding to Add Data Row, “Add Data Row: Value cannot be null. (Parameter ‘value’)”

we will not use the add data row activity. All lines will be used within an assign activity. Can you share with us a screenshot of your modeling?