简体   繁体   中英

How to extract all values from one key type of a json file?

I'm trying to learn how to do this (I can barely code), I'm not trying to get you (the wonderful and generous reader of my post) to do my job for me. Obviously full solutions are welcome but my goal is to figure out the HOW so I can do this myself.

Project - Summary Extract just the attachment file urls from a massive json file (I believe the proper term is "parse json strings").

Project - Wordy Explanation I'm trying to get all the attachments from a .json file that is an export of the entire Trello board I have. It has a specific key field for these attachments at the end of a json tree like below:

TrelloBoard.json
> cards 
>> 0
>>> attachments 
>>>> 0  
>>>>> url   "https://trello-attachments.s3.amazonaws.com/###/####/#####/AttachedFile.pdf"

(The first 0 goes up to 300+, representing each Trello card, the second 0 has never gone above 0, as it represents the number of attachments per card)

I've looked up tutorials online of how to parse strings from json files, but I haven't been able to get anything to print out (write) from those attempts. Seeing as I have over 100 attachments per month to download, a code would clearly be the best way to do it -- but I'm completely stumped on how and am asking you, dear reader, to help point me in the right direction.

Code Attempt

Any programming language is fine (I'm new enough to not be attached to any), but I've tried the following in python (among other codes) to no avail in Command Prompt.

import json

with open('G:\~WORK~\~Codes~\trello.json') as f:
  data = json.load(f)

# Output: {'cards': '0', 'attachments': '0', 'url': ['https://trello-attachments.s3.amazonaws.com']}
print(data)

Use python dict to get the needed value:

import json

with open('G:\~WORK~\~Codes~\trello.json') as f:
  data = json.load(f)
  url = data['url']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM