Master Using SQL with Python: Lesson 11 - Using JSON with SQLite

Поделиться
HTML-код
  • Опубликовано: 14 окт 2024
  • In this video, you will learn how to create, store, and retrieve JSON objects using Python and SQLite. JSON is a very popular way to share data and SQLite has powerful features to store and query JSON. In this video, I'll show you how to get data from a website in JSON format, store it in a SQLite table, retrieve the JSON, and perform queries on it.
    Slides and Code available at:
    github.com/bca...
    Download and Unzip the file.
    My video on installing and using SQLite Studio
    • Video

Комментарии • 31

  • @danmisener
    @danmisener 2 года назад +3

    Thanks for making this video, Bryan. It's the clearest example of working with JSON in SQLite using Python I've seen! Much appreciated!

  • @georgwagner5577
    @georgwagner5577 Месяц назад

    I used to work with pandas - I hate it. Time to switch :) Thank you, I love your guidance.

  • @user-lg4le8xr4s
    @user-lg4le8xr4s 7 месяцев назад

    Definitely would like more videos working with both JSON and REGEX in SQL

  • @notterboutuyer2781
    @notterboutuyer2781 Год назад

    i definitely like to see more about the json usage in sqlite/postgres with python. especially using twitter api v2. thanks for the series. it really helps. best.

  • @michaeleidson9210
    @michaeleidson9210 2 года назад

    Thanks Bryan! Add my vote to doing more sessions with Python/JSON --> into SQL Server, SQLite, & even Snowflake if you have the time!!! Thanks again for your great series!

  • @sherlockholmes676
    @sherlockholmes676 2 года назад +1

    exactly what I needed. Thanks Bryan!

    • @BryanCafferky
      @BryanCafferky  2 года назад

      YW. Check out the whole series. I think you may find it useful.

  • @OrigamOx
    @OrigamOx 2 года назад +1

    Thank you very much. Your explanations are very good

  • @Imaginativeone_DF
    @Imaginativeone_DF 3 года назад +2

    Would these efforts be this straightforward using JavaScript?

    • @BryanCafferky
      @BryanCafferky  3 года назад +3

      Well. It can be done using JavaScript but SQLite is built into Python and Python has a massive set of libraries for data analysis. I think Python is a stronger choice for data-centric work while JavaScript is the better choice for web/mobile apps. But either can be used in both cases.

  • @tiagocostadossantos6379
    @tiagocostadossantos6379 2 года назад

    Thanks Bryan!

  • @CarlosMoreno-vw4ir
    @CarlosMoreno-vw4ir 2 года назад

    Awesome video! Thanks so much…

  • @SAliGhasempouri
    @SAliGhasempouri 2 года назад +1

    Hi. Thanks for your great content.
    I use sqlite3 version 3.34 with python 3.8.
    I get error when using json extract:
    cursor.execute('''select json_extract(data, '$.name', '$.iso2Code', '$.id') from countries;''').fetchmany(8)
    OperationalError: no such function: json_extract

    • @BryanCafferky
      @BryanCafferky  2 года назад +1

      I used sqlite3.sqlite_version 3.37.0 and sqlite3.version 2.6.0.
      I assume you are running this in the Jupyter Notebook I put in GitHub? If so, looks like a library versioning issue so upgrading the SQLite libraries may fix it.

    • @SAliGhasempouri
      @SAliGhasempouri 2 года назад

      @@BryanCafferky thanks. Yes i used that one.
      By the way i tried to look for how to upgrade my sqlite but strangely i could not understand

    • @SAliGhasempouri
      @SAliGhasempouri 2 года назад +1

      @@BryanCafferky I fixed it. i upgraded and it works😎

    • @BryanCafferky
      @BryanCafferky  2 года назад

      @@SAliGhasempouri Awesome!

  • @izthed9117
    @izthed9117 2 года назад +1

    i get this issue when i try the panda lib
    Execution failed on sql '
    select json_extract(data, '$.id') as id,
    order by id,
    limit 5;': near "order": syntax error

    • @BryanCafferky
      @BryanCafferky  2 года назад +2

      Yep. It's a syntax error. I don't see a FROM clause and don't think the comma after order by id is needed. If that does not solve the issue I would reommend googling Python pnadas SQL jason_extract.

  • @jiweihe3413
    @jiweihe3413 2 года назад

    thank you. How can we json_extract a nested variable?

    • @jiweihe3413
      @jiweihe3413 2 года назад

      realize it can be done by json_extract(data, '$.var1.nested_var2') as var2. I wonder if we store the data in json format, will query be troublesome?

    • @BryanCafferky
      @BryanCafferky  2 года назад

      YW. See this blog. adatis.co.uk/parsing-nested-json-lists-in-databricks-using-python/

  • @paolorussi8739
    @paolorussi8739 3 года назад +1

    Why I'm getting "OperationalError: no such function: json_extract
    " without doing anything on the code! Getting mad:)

    • @BryanCafferky
      @BryanCafferky  3 года назад

      Why are you getting mad?

    • @paolorussi8739
      @paolorussi8739 3 года назад +1

      @@BryanCafferky I found that SQLite package was not updated, so it was not able to call JSON functions. I solved installing the latest version.
      Thanks a lot! Great video

    • @BryanCafferky
      @BryanCafferky  3 года назад +2

      @@paolorussi8739 Ok. The word "mad" threw me. I did not intend to anger people. But coding errors can happen from many causes and missing or out-of-date libraries is one. To solve errors, I had to get really good at googling. Calmly dealing with and solving bugs is a rare but essential skill to develop. Everybody hates hitting a bug but that is part of the work.

    • @OrigamOx
      @OrigamOx 2 года назад

      Thank you very much. You solved my problem ! :)

    • @jiweihe3413
      @jiweihe3413 2 года назад

      @@OrigamOx same here! thank you