logica icon indicating copy to clipboard operation
logica copied to clipboard

Sqlite: StructuredTest returns string instead of json object?

Open RAbraham opened this issue 4 years ago • 2 comments

%%logica StructureTest
@Engine("sqlite");
StructureTest(a: {x: 1, y: 2, z: { w: "hello", v: "world"}});
StructureTest(a: {x: 3, y: 4, z: { w: "bonjour", v: "monde"}});
print(StructureTest['a'].values[0])
print(type(StructureTest['a'].values[0]))
print(StructureTest['a'].values[0]['z']['w']) # <===== This is the line in the tutorial that fails
{"x":1,"y":2,"z":{"w":"hello","v":"world"}}
<class 'str'>

---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

<ipython-input-14-dbaa4016c4ed> in <module>()
      2 print(StructureTest['a'].values[0])
      3 print(type(StructureTest['a'].values[0]))
----> 4 print(StructureTest['a'].values[0]['z']['w'])

TypeError: string indices must be integers

RAbraham avatar Jul 23 '21 11:07 RAbraham

Yes, that's right. I'm afraid it will have to stay this way for a while. SQLite treats jsons as strings and there is no robust way to differentiate string from object.

We will need to explain it in documentation though.

EvgSkv avatar Jul 28 '21 15:07 EvgSkv

👍 please close at will.

RAbraham avatar Aug 04 '21 11:08 RAbraham