I would like to be able to determine if a JSON string will be parseable as a LIST or as a MAP before processing it.
Am I missing something, or is the only way to know is to test the first character?
"[" = LIST
"{" = MAP
code:
Dim json As JSONParser
json.Initialize(StdOut)
If json.IsInitialized Then
If StdOut.StartsWith("[") Then
For Each Program As Map In json.NextArray
'processing as a list of map
Next
Else
Dim Program As Map = json.NextObject
'processing as a map
End If
End If
That is how you look at it I guess. If it is an error, in my view, it can not be valid so a 'valid error' does not exist, it is just an error and badly formed Json. That is why you need the try catch.
Same here. We have several connections between e.g. our REST API and several other ones, all exchanging data with json. Our approach is that we do not try to 'fix' bad json. We pass it on to the vendor/client and they have to fix their code so they provide valid json. Just a different approach as we want to tackle the problem at its root.
B4X implementation of the "mayBeJSON" method from JSON Lib - https://github.com/jenkinsci/json-lib The method tests if the input String possibly represents a valid JSON String. This is handy as a check before running the JSONParser. Sub MayBeJSON(Input As String) As Boolean If Input.Length...