0

I have this JSON file, called my_file.json:

{
"t shirt": [
    "tee"
],
"neck": [
    "neckline"
],
"grey": [
    "gray"
]
}

I am reading it with:

f = open('my_file.json', 'r')
json.load(f)

I get the exception ValueError("No JSON object could be decoded"), as if the file wasn't valid JSON, which it actually is (even checked it with a validator).

What's wrong?

Jonathan Eunice
  • 21,653
  • 6
  • 75
  • 77
mar tin
  • 9,266
  • 23
  • 72
  • 97
  • 5
    Check for a BOM marker. The BOM marker is a Unicode character with code point U+FEFF that specifies the endianness of an Unicode text stream. It makes no sense for UTF-8 but some text editors put this in the beginning of the file (and it is invisible). – Paulo Scardine Jul 29 '15 at 21:32
  • 1
    Looks like a dupe of http://stackoverflow.com/questions/13156395/python-load-json-file-with-utf-8-bom-header – Paulo Scardine Jul 29 '15 at 21:34
  • If you print the `repr` output of each line the file you will see exactly what is there – Padraic Cunningham Jul 29 '15 at 21:41
  • 1
    I think Paulo is correct, the above example should works without a problem. – TomDotTom Jul 29 '15 at 21:41

0 Answers0