A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Check whether following json is valid or invalid. If Invalid correct it
Q:

Check whether following json is valid or invalid. If Invalid correct it

0

Check whether following json is valid or invalid. If Invalid correct it

{ 
   "company":{ 
      "employee":{ 
         "name":"emma",
         "payble":{ 
            "salary":7000
            "bonus":800
         }
      }
   }
}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution1:

Python provides The json.tool module to validate JSON objects from the command line. Run the following command.

Command: echo "JSON DATA" | python -m json.tool

echo { "company":{ "employee":{ "name":"emma", "payble":{ "salary":7000 "bonus":800} } } } | python -m json.tool

Output:

Expecting ',' delimiter: line 1 column 68 (char 67)

Just add ',' after "salary":7000 to solve the error.

Solution2:

import json

def validateJSON(jsonData):
    try:
        json.loads(jsonData)
    except ValueError as err:
        return False
    return True

InvalidJsonData = """{ "company":{ "employee":{ "name":"emma", "payble":{ "salary":7000 "bonus":800} } } }"""
isValid = validateJSON(InvalidJsonData)

print("Given JSON string is Valid", isValid)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now