dimanche 31 janvier 2016

Right way to store `JSON` object in a `sqlite`, nodejs

I don't know the right way to store JSON object in a sqlite text field, using nodejs sqlite3 driver. I have tried the following ways:

  1. I simply write JSON object without any conversion. When I look into the table, jstr value looks like {"melicode":9876543210} but after retrieve it JSON.parse(jstr) fails with SyntaxError: Unexpected token m
  2. Then before write it to the table I tried JSON.stringify(jobj), now jstr value looks like {\"melicode\":9876543210} but when I try to convert it, JSON.parse(jstr) fails with SyntaxError: Unexpected token \

    It looks like sqlite3 omits double quotes when retrieve TEXT, no matter it has a '\' char before or not.

Aucun commentaire:

Enregistrer un commentaire