simonw / sqlite-utils

Python CLI utility and library for manipulating SQLite databases
https://sqlite-utils.datasette.io
Apache License 2.0
1.58k stars 106 forks source link

Doublebyte content is unicode-escaped in JSON output #625

Open oli opened 3 months ago

oli commented 3 months ago

test.json

[
    {
        "id": 123,
        "text": "Japanese 日本語"
    },
    {
        "id": 223,
        "text": [
            "Japanese 日本語"
        ]
    }
]

Import

sqlite-utils insert test.db text test.json --pk=id

Query using sqlite-utils

sqlite-utils test.db "select * from text"
[{"id": 123, "text": "Japanese \u65e5\u672c\u8a9e"},
 {"id": 223, "text": "[\"Japanese \u65e5\u672c\u8a9e\"]"}]

sqlite-utils test.db "select * from text" --csv
id,text
123,Japanese 日本語
223,"[""Japanese 日本語""]"

I assume this is something to do with “ensure ascii” for JSON, but is there any way I can get non-escaped content strings in sqlite-utils JSON output? Thanks!