Skip to content
Advertisement

dump json into yaml

I got a .json file (named it meta.json) like this:

JavaScript

I would like to convert it to a .yaml file (named it meta.yaml) like :

JavaScript

What I have done was :

JavaScript

But sadly, what I got is following:

JavaScript

Why?

Advertisement

Answer

pyyaml.dump() has an allow_unicode option that defaults to None (all non-ASCII characters in the output are escaped). If allow_unicode=True, then it writes raw Unicode strings.

JavaScript

Bonus

You can dump JSON without encoding as follows:

JavaScript
Advertisement