Type of object value in JSON in Xojo

I used the column tag. I also needed the ‘names’ so I’m doing this:

Dim firstline As Boolean = True
Dim i As Integer = 0
Dim node As JSONItem

For Each name As String In J.Names
  
  node = J.Child(name)
  ParamChgLB2.AddRow
  ParamChgLB2.RowTag(ParamChgLB2.LastIndex) = name // we'll need this later...
  
  
  For Each subname As String In node.Names
    
    If firstline Then
      ParamChgLB2.Heading(i) = subname
      ParamChgLB2.ColumnTag(i) = subname + Chr(9) + Str(node.value(subname).Type) // we'll need this later too!
    End If
    
    ParamChgLB2.Cell(ParamChgLB2.LastIndex, i) = node.value(subname)
    i = i + 1
    
  Next
  
  firstline = False
  i = 0
  
Next

Then in ListBox.CellAction I have:

Dim rt As String = Me.RowTag(row)
Dim ct() As String = Me.ColumnTag(column).StringValue.Split(Chr(9))

Dim node As JSONItem = JSON.Child(rt)
Dim nodeVal As Variant = node.value(ct(0))
Dim coltype As Integer = Val(ct(1))

System.DebugLog("Editing: " + nodeVal.StringValue + " to " + Me.Cell(row, column))

System.DebugLog("node Type before: " + Str(nodeVal.Type) + ", Col type = " + Str(coltype))

nodeVal = Me.Cell(row, column)
Select Case coltype
Case Variant.TypeInteger
  node.value(ct(0)) = nodeVal.IntegerValue
Case Variant.TypeString
  node.value(ct(0)) = nodeVal.StringValue
Case Variant.TypeBoolean
  node.value(ct(0)) = nodeVal.BooleanValue
End Select

System.DebugLog("node Type after:  " + Str(node.value(ct(0)).Type))

Works a treat! Thanks, Gents!!

The short answer is: No.
The long answer is: You have to do it yourself. You can not determine the value type simply putting the value into a variant.
But it’s not too complicated, JSON only supportes five basic value types:

  • string
  • number (double)
  • integer
  • boolean
  • null (nil)

If the value begins with double quotes than it’s a string. Otherwise you parse “true”, “false” and “null”. The rest is a number; integer or double/currency (if it contains a dot).