Problems with JSON (xojo 2021 release 1.1)

I am developing a web application in xojo 2021 release 1.1, I have a problem with json, the code works fine in xojo 2020 release 2.1., I can’t find a way to make it work.


var row_j As new JSONItem
row_j.Value(“empleado_codigo”) = txtCodigo.Value
row_j.Value(“nombres”) = txtNombres.Value
row_j.Value(“apellidos”) = txtApellidos.Value
row_j.Value(“cedula”) = txtCedula.Value
If dateNacimiento.Value = Nil Then
row_j.Value(“nacimiento_fecha”) = Nil

row_j.Value(“nacimiento_fecha”) = dateNacimiento.Value.SQLDate

End If

var file_j As new JSONItem
file_j.ChildAt(0) = row_j
Catch e as JSONException
MessageBox(“error:” + e.Message)

end try

Do you get an error?
Is the JSON empty?
Can you share a sample? using Dropbox to test


Error message, Until yesterday I had a memory, what it said

Json Empty, NO, I can see its content.

{“employee_code”: “T00001”, “names”: “JORGE LUIS”, “surnames”: “AGUILAR SERAQUIVE”, “cedula”: “1234567890”, “birth_date”: “1996-07-06”}

I prepare an example and share it.

Your code is almost right. You need to initialize the new JSONItem as an array:

var file_j As new JSONItem("[]")

And you need to use Add instead of ChildAt because it doesn’t have any elements yet.


See also Feedback case 65235 - jsonitem add should change empty object to array or raise exeception.

Would be nice if empty JSONItem can turn to array or object as needed.

Unfortunately it can’t. Because each underlying object is a dictionary or array now instead of a custom object,

Here’s an example of the problem:

Var x as new JSONItem
x.child("people") = new JSONItem
Var y = x.child("people")

When y is assigned on line 3, it is pointing to a Dictionary, because the creation of that object was just a JSONItem. When you call add on line 4, if we were to change the object into an array, the reference that says that it’s contained in x still points to the Dictionary that was created on line 1. You end up with y being an orphaned object which no longer affects or original structure.

Maybe the class should not have been changed, instead a new class like JSONObject could have been made the new way. The JSONItem is now broken and changed, result broken projects.