For some time I have been using an UnmanagedExports wrapper around JsonTextReader and JsonTextWriter from Json.NET which was quite handy but had limitations.
Today I have added the ability to Querying JSON with SelectToken which so far is pretty damn awesome!
Consider this JSON data for input:
{
"solutions": [
{
"departureTime": "08:24",
"rego": "ABC123",
},
{
"departureTime": "09:24",
"rego": "ZZZ321",
}
]
}
I can do things like this:
Json.InitJObject(jsonData)
i=-1 ! remember zero based arrays in .NET
LOOP
i+=1
vehicleRego = Json.SelectToken('solutions[' & i & '].rego')
IF vehicleRego = ''
! We are done with the solutions, see ya!
BREAK
END
Debug.Message('Vehicle Rego: ' & vehicleRego)
END
Json.KillJObject()
Of course at the moment it considers everything a string on the .NET side and relies on Clarion data conversions which might bite me at some point but I image you could do something like Json.SelectToken('solutions[0].ChildSomething[22].MoneyField', EQUATE_TYPE:DECIMAL)
and add a bit of handling on the other end to deal with different data types or whatever.
Anyway, I thought is was pretty cool and worth a share. With this I can react to incoming Json data in a very dynamic way without lots of pain. Yay!