TheWaveLad
TheWaveLad

Reputation: 1026

Converting YAML to JSON with Python: <block end> found

I'm trying to convert the following example yaml file into json

test.yaml

- fields: {name: "Test", nr: "000"}
    model: testmodel
    pk: "1"

However, calling

python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), 
sys.stdout, indent=4)' < test.yaml > test.json

returns an error

"expected <block end>, but found %r" % token.id, token.start_mark)
yaml.parser.ParserError: while parsing a block mapping
  in "<stdin>", line 1, column 3
expected <block end>, but found '<block mapping start>'
  in "<stdin>", line 3, column 5

What's wrong with my yaml-file?

Upvotes: 3

Views: 7152

Answers (1)

swstephe
swstephe

Reputation: 1910

Your indentation is wrong. You probably meant:

- fields: {name: "Test", nr: "000"}
  model: testmodel
  pk: "1"

Upvotes: 3

Related Questions