Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading field of type JSON returns invalid value #1749

Open
JakobJingleheimer opened this issue Jan 14, 2024 · 0 comments
Open

Reading field of type JSON returns invalid value #1749

JakobJingleheimer opened this issue Jan 14, 2024 · 0 comments
Labels

Comments

@JakobJingleheimer
Copy link

JakobJingleheimer commented Jan 14, 2024

Issue Summary

I have a field (tags) that is of type JSON. I insert a record with the json value stringified. That appears to succeed. However, when I read the record back out, the value is missing inner quotes around values that need them.

The actual result is unusable.

Steps to Reproduce

await db.run(`
CREATE TABLE IF NOT EXISTS foo (
  _id CHAR(6) NOT NULL PRIMARY KEY,
  tags JSON DEFAULT []
);
`);
const _id = uid(6);
const tags = ["groceries"];
await db.run(`INSERT INTO foo (_id,tags) VALUES (${uid},${JSON.stringify(tags)});`);
const record = await db.run(`SELECT * FROM foo WHERE _id = ${uid};`);

console.log(record);

Actual result:

{
  _id: 'a96ce3',
  tags: '[groceries]',
}

Expected result:

{
  _id: 'a96ce3',
  tags: '["groceries"]',
}

OR

{
  _id: 'a96ce3',
  tags: ["groceries"],
}

Version

5.1.7

Node.js Version

21.5.0

How did you install the library?

npm i -S sqlite3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant