noborus / trdsql

CLI tool that can execute SQL queries on CSV, LTSV, JSON, YAML and TBLN. Can output to various formats.
https://noborus.github.io/trdsql/
MIT License
1.94k stars 73 forks source link

Fixed JSON sample in README #202

Closed ser1zw closed 1 year ago

ser1zw commented 1 year ago

I got errors below when trying 4.10. JSON sample in README.md.

$ cat sample2.json
[
    {
      "id": 1,
      "name": "Drolet",
      "attribute": { "country": "Maldives", "color": "burlywood" }
    },
    {
      "id": 2,
      "name": "Shelly",
      "attribute": { "country": "Yemen", "color": "plum" }
    },
    {
      "id": 3,
      "name": "Tuck",
      "attribute": { "country": "Mayotte", "color": "antiquewhite" }
    }
]

$ trdsql -ijson "SELECT id, name, JSON_EXTRACT(attribute,'$country'), JSON_EXTRACT(attribute,'$color') FROM sample2.json"

Using SQLite3 driver:

2022/11/19 07:04:22 export: JSON path error near ''

Using MySQL driver:

2022/11/19 07:04:46 export: Error 3143 (42000): Invalid JSON path expression. The error is around character position 0.

The correct SQL is probably here.

$ trdsql -ijson "SELECT id, name, JSON_EXTRACT(attribute,'$.country'), JSON_EXTRACT(attribute,'$.color') FROM sample2.json"
1,Drolet,Maldives,burlywood
2,Shelly,Yemen,plum
3,Tuck,Mayotte,antiquewhite

Version:

$ trdsql --version
trdsql version v0.10.1
noborus commented 1 year ago

Thank you! you are right.