You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm trying to access the result of a query via json but it seems the output isn't propery escaped.
my table contains a regex but that's irrelevant, I think, it's just a VARCHAR.
my failed attempt:
const q = await vg.coordinator().query('FROM allregexes;', {type: "json", cache: false});
JSON.parse(q); // fails: Bad escaped character in JSON at position 32
console.log(q.toString()); // because the \d should be escaped as \\d {"regex": "^(?P<DD>0[1-9]|[1-2]\d|3[0-1])...
is this the correct way to access the query results via JSON, or did i find a bug?
curently, my workaround looks like this but would prefer json
const q = await vg.coordinator().query('FROM allregexes;', {type: "arrow", cache: false});
for (const entry of q) {
console.log(entry.regex)
}
is this the right approach?
thanks!
The text was updated successfully, but these errors were encountered:
Thanks for reporting the issue. Can you share a basic table CREATE and/or INSERT query with data that replicates the issue? (A single row table should be fine!) Then we can test directly on our end and see where in the pipeline the bug may arise.
vg.coordinator().exec('CREATE TABLE test AS SELECT \'^(?P<DD>0[1-9]|[1-2]\\d|3[0-1])/\' as teststring' );
vg.coordinator().query("SELECT teststring from test;", {type: "json", cache: false})
.then((q) => {
console.log(q.toString());
const t = JSON.parse(q);
console.log(t);
});
results in:
{"teststring": "^(?P<DD>0[1-9]|[1-2]\d|3[0-1])/"}
VM262:1 Uncaught (in promise) SyntaxError: Bad escaped character in JSON at position 37
at JSON.parse (<anonymous>)
at index.html:57:19
```
Thanks! I tested this and the problem is that the return value of the query is already parsed. Instead of calling JSON.parse, simply use the returned q array.
If using a DuckDB server (socket connector), the result will be sent back as a JSON string and parsed internally. Meanwhile, DuckDB-WASM (wasm connector) only produces Arrow tables, so when json is requested the Arrow table is coerced to a JS-Array-of-Objects compatible array.
Hi, I'm trying to access the result of a query via json but it seems the output isn't propery escaped.
my table contains a regex but that's irrelevant, I think, it's just a VARCHAR.
my failed attempt:
is this the correct way to access the query results via JSON, or did i find a bug?
curently, my workaround looks like this but would prefer json
is this the right approach?
thanks!
The text was updated successfully, but these errors were encountered: