Skip to content

Instantly share code, notes, and snippets.

@narenaryan
Last active September 13, 2022 12:02
Show Gist options
  • Select an option

  • Save narenaryan/1668d1d0628992cd3280c70eb5761604 to your computer and use it in GitHub Desktop.

Select an option

Save narenaryan/1668d1d0628992cd3280c70eb5761604 to your computer and use it in GitHub Desktop.
{
"languages": {
"python": {
"name": "Python",
"author": "Guido Van Rossum",
"usedFor": ["Scripting", "Web Development", "Text processing", "Data Science"]
},
"go": {
"name": "Go",
"author": "Google",
"usedFor": ["Devops Tooling", "Low-latency Servers", "command-line Tools"]
}
}
}
import json
# Open a file pointer
fp = open("data.json", "r")
# Decoded result
result = json.load(fp)
languages = result.get("languages")
if languages:
golang = languages.get("go")
if golang:
name = golang.get("name")
count = len(golang.get("usedFor"))
# Prints 'Go is mainly used for 3 reasons'
print(f"{name} is mainly used for {count} reasons")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment