Python-requests: .json() example

Syntax

.json()

requests .json() example

import requests

# Get Request
req = requests.get("https://api.dictionaryapi.dev/api/v2/entries/en/word")

# Print response Json
print(req.json())

Output:

[{'word': 'word', 'phonetic': 'wəːd', 'phonetics': [{'text': 'wəːd', 'audio': '//ssl.gstatic.com/dictionary/static/sounds/20200429/word--_gb_1.8.mp3'}], 'origin': 'Old English, of Germanic origin; related to Dutch woord and German Wort, from an Indo-European root shared by Latin verbum ‘word’.', 'meanings': [{'partOfSpeech': 'noun', 'definitions': [{'definition': 'a single distinct meaningful element of speech or writing, used with others (or sometimes alone) to form a sentence and typically shown with a space on either side when written or printed.', 'example': "I don't like the word ‘unofficial’", 'synonyms': ['term', 'name', 'expression', 'designation', 'locution', 'turn of phrase', 'idiom', 'appellation', 'vocable'], 'antonyms': []}, {'definition': 'a command, password, or signal.', 'example': 'someone gave me the word to start playing', 'synonyms': ['instruction', 'order', 'command', 'signal', 'prompt', 'cue', 'tip-off', 'go-ahead', 'thumbs up', 'green light', 'high sign', 'decree', 'edict', 'mandate', 'bidding', 'will'], 'antonyms': []}, {'definition': "one's account of the truth, especially when it differs from that of another person.", 'example': 'in court it would have been his word against mine', 'synonyms': [], 'antonyms': []}, {'definition': 'the text or spoken part of a play, opera, or other performed piece; a script.', 'example': 'he had to learn his words', 'synonyms': ['script', 'text', 'lyrics', 'libretto'], 'antonyms': []}, {'definition': 'a basic unit of data in a computer, typically 16 or 32 bits long.', 'synonyms': [], 'antonyms': []}]}, {'partOfSpeech': 'verb', 'definitions': [{'definition': 'express (something spoken or written) in particular words.', 'example': 'he words his request in a particularly ironic way', 'synonyms': ['phrase', 'express', 'put', 'couch', 'frame', 'set forth', 'formulate', 'style', 'say', 'utter', 'state'], 'antonyms': []}]}, {'partOfSpeech': 'exclamation', 'definitions': [{'definition': 'used to express agreement or affirmation.', 'example': "Word, that's a good record, man", 'synonyms': [], 'antonyms': []}]}]}, {'word': '-word', 'phonetics': [{}], 'meanings': [{'partOfSpeech': 'combining form', 'definitions': [{'definition': "denoting a slang word, or one that may be offensive or have a negative connotation, specified by the word's first letter.", 'example': 'the F-word', 'synonyms': [], 'antonyms': []}]}]}, {'word': 'the Word', 'phonetics': [{}], 'meanings': [{'definitions': [{'definition': 'the Bible, or a part of it.', 'synonyms': [], 'antonyms': []}, {'definition': 'Jesus Christ.', 'synonyms': [], 'antonyms': []}]}]}]

 

import requests

# Get Request
req = requests.get("https://pyonlycode.com")

# Print response No Json
print(req.json())

Output:

raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)