how to get json data from duckdb #326
-
|
When I use @duckdb/node-api to read JSON data from a DuckDB database, it returns a string type. How can I make it directly return the JSON type without the need for type conversion? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
DuckDB represents JSON data as strings. The JSON type is really just a VARCHAR, but with a type alias, "JSON". If you inspect the column type of the result, using JSON values are returned as JS strings; if you want to convert them to JS objects, you'll have to use JSON.parse. The |
Beta Was this translation helpful? Give feedback.
DuckDB represents JSON data as strings. The JSON type is really just a VARCHAR, but with a type alias, "JSON".
If you inspect the column type of the result, using
columnType(index)orcolumnTypes(), you can read thealiasfield of theDuckDBTypeobject. This can be used to distinguish JSON VARCHARs from normal VARCHARs.JSON values are returned as JS strings; if you want to convert them to JS objects, you'll have to use JSON.parse.
The
getRowsJsonmethod converts the returned data, of any type, to JSON-compatible JS object; it doesn't convert from JSON.