I am trying to load my json file with the stdin
using the Windows command line: python algo.py < number.json
and using json.loads(sys.stdin)
in my script but it fails.
However, I can load my json with
with open('number.json',encoding='utf-8-sig') as f:
n = json.loads(f)
Exception raised when using json.loads(sys.stdin)
:
the JSON object must be str, bytes or bytearray, not TextIOWrapper
Exception raised when using json.load(sys.stdin) or json.loads(sys.stdin.read())
:
Expecting value: line 1 column 1 (char 0)
Anyone encountered the same issue? I read multiple posts in this forum prior asking help.
Here is the json file:
[
{
"x": 1,
"y": 4,
"z": -1,
"t": 2
},
{
"x": 2,
"y": -1,
"z": 3,
"t": 0
}
]