1

Here's the method:

def load(self, path):
        json_data = open(path, "r")
        self.data = load(json_data)
        return self.data

Here's the file (Which was saved with utf-8 encoding):

{
"False": "Falso",
"None": "Nulo",
"True": "Verdadeiro",
"as": "como",
"assert": "afirmar",
"break": ["quebrar", "interromper", "parar"],
"class": "classe",
"continue": "continuar",
"def": ["func", " f ", "função"],
"del": ["deletar", "excluir"],
"elif": ["senão se", "senao se"],
"else": ["senão", "senao"],
"except": ["exceto", "excetuar"],
"finally": "finalmente",
"for ": "para ",
"from ": "de ",
"if ": ["se ", "caso "],
"if(": ["se(", "caso("],
"import": "importar",
" in ": [" em ", " no ", " na ", " nos ", " nas "],
" is ": " é ",
"nonlocal": "nãolocal",
" not ": " não ",
" or ": " ou ",
"pass": ["passar", "prosseguir"],
"raise": ["levantar", "erguer"],
"return": "retornar",
"try": "tentar",
"while": "enquanto",
"with": "com",
"print": ["escrever", "imprimir", "printar", "mostrar"],
" and ": " e "
}

And here's the error:

ValueError: Expecting value: line 1 column 1 (char 0)

If I encode it as "ANSI", this error goes away. I don't understand, char 0 is {.

Ericson Willians
  • 7,606
  • 11
  • 63
  • 114
  • possible duplicate of [Python load json file with UTF-8 BOM header](http://stackoverflow.com/questions/13156395/python-load-json-file-with-utf-8-bom-header) – ivan_pozdeev Sep 28 '15 at 23:47

1 Answers1

2

BOM must be the culprit. Open the file with codecs.open(path,"r","utf-8-sig") or autodetect the encoding to open with e.g. as per Reading Unicode file data with BOM chars in Python.

Community
  • 1
  • 1
ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152