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

Special handling for SQLite column of type JSON #579

Open
asg017 opened this issue Jul 25, 2023 · 1 comment
Open

Special handling for SQLite column of type JSON #579

asg017 opened this issue Jul 25, 2023 · 1 comment

Comments

@asg017
Copy link
Contributor

asg017 commented Jul 25, 2023

sqlite-utils should detect and have specially handling for column with a JSON column. For example:

CREATE TABLE "dogs" (
  id INTEGER PRIMARY KEY,
  name TEXT,
  friends JSON 
);

Automatic Nesting

According to "Nested JSON Values", sqlite-utils will only expand JSON if the --json-cols flag is passed. It looks like it'll try to json.load all text column to test if its JSON, which can get expensive on non-json columns.

Instead, sqlite-utils should be default (ie without the --json-cols flags) do the maybe_json() operation on columns with a declared JSON type. So the above table would expand the "friends" column as expected, withoutthe --json-cols flag:

sqlite-utils dogs.db "select * from dogs" | python -mjson.tool
[
    {
        "id": 1,
        "name": "Cleo",
        "friends": [
            {
                "name": "Pancakes"
            },
            {
                "name": "Bailey"
            }
        ]
    }
]

I'm sure there's other ways sqlite-utils can specially handle JSON columns, so keeping this open while I think of more

@rsyring
Copy link

rsyring commented Jan 22, 2024

I just created #612, which is very similar to this issue and recommends automatically handling JSON deserialization. I only kept it separate because I was mostly contemplating library usage and this issue seems to be focused on CLI usage.

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

No branches or pull requests

2 participants