[PYTHON] Generate URL query from JSON

Motivation

I touched Python's Request module for the first time. ** Can I create a query from JSON **? !! It's convenient! Great! → Reproduced with Shortcuts: relaxed:

Whole flow

This time, the URL for extracting the id from the Apple Music URL and requesting it to the iTunes Search API Is generated. ![079E3100-6A2E-40CC-9328-D34267E2BF38.jpeg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/561438/42b96181-0db6-e9e0-57a9-d50df4d789ac .jpeg)

Get the query string from the entered URL

44E3B10A-2C8A-40DD-865B-45EF3ECECAD1.jpeg Specify to get the query with [Get URL component]. ʻI = 40284574` is output.

Put a value in the dictionary for queries

7AAC9F70-FF78-4B4E-A352-DC3990537D20.jpeg出力するURLのクエリーを I want to set country = jp & lang = ja_jp & id = 40284574, so enter the value that matches it. This variable * i * is the magic variable output from the [Get component of URL] above. Like the GIF below

  1. Tap the magic variable
  2. Set the type to dictionary
  3. Specify the key ʻi This action allows you to convert ** ʻi = 40284574 to{"i": "40284574"}and treat it as the value of the key ʻi`. ** (Very convenient) By the way, if you try to do the same without using this tech, it will increase by 2 actions (see the image below). It is troublesome, so I strongly recommend using the above technique. 1AD0CB83-761E-4F37-84E2-2EFB9D776219.jpeg

Get the value for each key in the dictionary and pair it

92DC4083-9E66-4EEB-8D68-A1F4930D0378.jpeg Put the [dictionary] keys (country, lang, ʻid) in [repeat each item]to pair with the corresponding value. Using the technique above, treat the magic variables in the dictionary as a list (array) of keys. ![7D92D38F-9251-4B78-8026-FD98D199981B.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/561438/40776e22-3086-bff5-e5b6-1abef73cee05.gif) Output a list by connecting keys and values with'=' in[Repeat each item]. We've combined this list with [Merge Text]` using'&' and plunged into the query part of the URL.

Link to this shortcut

Recommended Posts

Generate URL query from JSON
Script to generate directory from json file
How to generate a Python object from JSON
Convert Select query obtained from Postgre with Go to JSON
Query Athena from Lambda Python
Extract specific data from complex JSON
Generate daily reports from Google Calendar
Automatically generate collage from image list
[Beginner] Get from Django Query database
Generate a Pre-Signed URL with golang
Generate S3 signed URL with boto