How to print index (Row number) while conversion error during json.loads Panda Dataframe

Solution 1:

You can create a custom function where you wrap the json.loads call in a try/except and then call this function inside apply. See also this answer.

def is_valid_json(s):
    try:
        json.loads(s)
    except (json.JSONDecodeError, ValueError):
        return False
    return True

# Mark valid JSON strings
valid = orgdf['data'].apply(is_valid_json)

# Extract indices with _invalid_ strings
invalid_indices = valid[~valid].index