Check both, the key existence and its length:

import json, sys

obj=json.load(sys.stdin)

if not 'results' in obj or len(obj['results']) == 0:
    exit(0)
else:
    exit(1)
Answer from Thiago Rossener on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › check-if-python-json-object-is-empty
Check If Python Json Object is Empty - GeeksforGeeks
July 23, 2025 - In this article, we explored three different methods to check if a JSON object is empty in Python.
Top answer
1 of 3
2

You're misunderstanding how in works. in checks to see if a key exists in a dictionary, it does not index into a dictionary. That's what the square brackets do.

if 'title_jpn' in json_data['gmetadata'][0] is not "":

The above line will not evaluate as you expect. It should be.

if json_data['gmetadata'][0]['title_jpn'] is not "":

This can be further simplified because empty strings '' always evaluate to False in python. So instead of checking if the string is not empty, just check if it has any value at all like the following:

if json_data['gmetadata'][0]['title_jpn']:

If you're trying to guard against the fact that title_jpn might be optional and not always exist, you need to do two conditions in your if statement (which I think is what you were originally trying to do):

if 'title_jpn' in json_data['gmetadata'][0] and json_data['gmetadata'][0]['title_jpn']:

The above line first checks if the title_jpn key is present before trying to check if it's value is empty. This can be further simplified using the dictionary .get() method which allows you to supply a default.

if json_data['gmetadata'][0].get('title_jpn', None):

The above will check if title_jpn is in the dictionary and return the value if it does, or None as a default if it does not. Since None is interpreted as False in python, the if block will not run, which is the desired behaviour.

dict.get(key, default=None)

However, since .get() automatically sets the default value to None, you can simply do the following.

if json_data['gmetadata'][0].get('title_jpn'):
2 of 3
0

Your .get won't work, since this applies to dictionaries. As far as I know, "In" won't work either since this is the syntax for a For loop. Probably you want the "Find" method, since this matches a substring within a longer string (which is your goal, if I understand correctly). It'll return minus one if the string isn't found. So in your case, example use:

if json_data['gmetadata'][0].find('title_jpn') != -1:
🌐
GeeksforGeeks
geeksforgeeks.org › python › check-if-json-object-has-empty-value-in-python
Check if Json Object has Empty Value in Python - GeeksforGeeks
July 23, 2025 - In this example, below code employs the json and jsonpath_ng modules to process a JSON string (json_data). It loads the data into a Python dictionary (parsed_json) and utilizes a JSONPath expression to find elements with null or empty values. The result is a boolean value indicating whether the JSON object contains such values,
🌐
FreeKB
freekb.net › Article
Determine if JSON key contains an empty list
On the other hand, if the list is not empty. #!/usr/bin/python3 import json raw_json = '{ "foo": [ "Hello", "World" ] }' try: parsed_json = json.loads ( raw_json ) except Exception as exception: print(f"Got the following exception: {exception}") if len(parsed_json['foo']) == 0: print("The foo key contains an empty list") else: print("The foo key does NOT contain an empty list")
🌐
UiPath Community
forum.uipath.com › help › studio
Check if an json array is empty - Studio - UiPath Community Forum
April 5, 2020 - Anyone knows how to check an json array is empty? I have gathered a few json arrays but some of them are empty, could anyone advise me how to verify if any json array is empty? Regards, Victor
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 36861749 › checking-whether-a-json-dictionary-is-empty-or-not-and-storing-in-a-list
python - Checking whether a JSON dictionary is empty or not and storing in a list - Stack Overflow
Then I save it in a python list and put it in an Excel sheet using openpyxl. Here is the catch. While loading the values, If there is no response from API in case of a deleted instagram account,where the JSON will be empty, I want to store "ACC deleted" in the list.
🌐
CopyProgramming
copyprogramming.com › howto › check-if-json-is-empty-python-code-example
Check If JSON Is Empty in Python: Complete Guide with 2026 Best Practices
December 21, 2025 - An empty JSON object—represented as {} in JSON syntax—converts to an empty Python dictionary when parsed. The simplest and most Pythonic way to check if a JSON object is empty is using the not operator: if not json_obj: returns True for empty dictionaries, while len(json_obj) == 0 and json_obj ...
🌐
IQCode
iqcode.com › code › javascript › how-to-check-if-a-json-object-is-empty
how to check if a json object is empty Code Example
can json exist as an empty value check empty json object javascript check Empty JSON object in python how to check if json empty check if json object is empty jquery check if json object has empty values javascript check if json object empty js check if json object is empty check if json stringify is empty javascript check if empty json json get if empty but {} json get if empty detect empty json find json is empty check if json object is empty js check if empty json javascript check if json object is null or empty json check for empty object javascript if json object is empty javascript if js
🌐
Quora
quora.com › How-do-I-check-if-an-array-is-empty-in-Python
How to check if an array is empty in Python - Quora
Answer (1 of 12): I am going to assume you are talking about lists (Python does have arrays, but they are very different to lists). Three ways : 1 Test the truthiness If you know the item is a list you do : [code]if not my_list: print(‘List is empty’) [/code]Empty containers (lists,sets,t...
🌐
Cloudera Community
community.cloudera.com › t5 › Support-Questions › How-to-check-if-JSON-content-is-null-or-empty › m-p › 237344
How to check if JSON content is null (or empty)? - Cloudera Community - 237344
August 17, 2020 - To loosely check if the variable is null, use a double equality operator(==). The double equality operator can not tell the difference between null and undefined, so it counts as same.
🌐
Quora
quora.com › How-do-you-declare-an-empty-JSON-in-Python
How to declare an empty JSON in Python - Quora
Answer (1 of 4): JSON is a serialization format that can represent certain kinds of objects as strings. An empty string is not a valid JSON representation of anything. If you try to decode an empty string using Python's standard [code ]json[/code] module, you'll get an error: [code]>>> import j...
🌐
Python Forum
python-forum.io › thread-27694.html
empty json file error
I wrote this and since it creates an empty file it give me an error. with open('food.json', 'r+') as file: food = json.load(file)Error:Traceback (most recent call last): File 'c:/Users/User/MyStuff/mltipls.py', line 4, in foo...