An aim of a research project I am doing using python is that my results are as accessible as possible. As a result, I am converting all my results to JSON so that future researchers who might want to use different languages can access and manipulate my data easily. At present, I am storing the data (YouTube comments data) in Python as multiple nested dictionaries/lists and then writing it to a JSON file:
import requests
import json
params = {
'part': 'snippet,replies',
'maxResults': 100,
'videoId': ********,
'textFormat': 'plainText',
'key': ***********
}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
}
comments_data = requests.get('https://www.googleapis.com/youtube/v3/commentThreads', params=params, headers=headers)
results = comments_data.json()
comments_list = ()
for item in results("items"):
comment = item("snippet")("topLevelComment")
author = comment('snippet')("authorDisplayName")
text = comment('snippet')("textDisplay")
likes = comment('snippet')("likeCount")
reply_count = item('snippet')('totalReplyCount')
comments_list.append({ #appends comment as a dictionary
"author" : author,
"text": text,
"likes": likes,
"reply_count": reply_count
})
if 'replies' in item.keys(): #checks if a comment has any replies
comments_list(-1).update({"replies":()})
for reply in item('replies')("comments"):
rep_author = reply('snippet')("authorDisplayName")
rep_text = reply('snippet')("textDisplay")
rep_likes = reply('snippet')("likeCount")
comments_list(-1)('replies').append({ #appends replies to latest entry in comments_list (aka its parent)
"author" : rep_author,
"text": rep_text,
"likes": rep_likes
})
with open("comments.json, "w", encoding="utf8") as f:
json.dump(comments_list, f, ensure_ascii=False)
As you can see, I am storing information about the comments, in particular the replies, as nested dictionaries.
I only have experience with Python, so I am unsure if other languages would struggle to process this data or not. Can anyone shed some light?