Unable to dump blocks without having quotes on keys
See original GitHub issueI am trying to dump JSON data into YAML in a way that makes is very easy to read by humans (as this goes to some logs).
Some of the values contain multiline strigs (stderr/stdout) and there is a must to avoid wrapping them.
data = json.loads("""{"key":"foo\\nbar"}""")
output = yaml.safe_dump(data,
allow_unicode=True,
default_flow_style=False,
canonical=False,
default_style="|")
print(output)
output = yaml.safe_dump(data,
allow_unicode=True,
default_flow_style=False,
canonical=False,
default_style=None)
print(output)
First formatting:
"key": |-
foobar
Second option:
key: 'foo
bar'
It seem that with default_style="|"
I do get the desired wrapping of multiline values but I lose the simplicity of the unquoted lines.
How can I get something like below?
key: |
foo
bar
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:7
Top Results From Across the Web
Ruamel Yaml dump in Python: Need to ensure specific keys ...
Issue With Current Solution: The keys are ever changing and new keys are constantly being added, but the data structure will always remain...
Read more >thesis know-how – beware the quote dump | patter
A quote dump is when the writer inserts a very large extract of someone ... And one or two quotations without any commentary...
Read more >Strings in YAML - To Quote or not to Quote | tinita [blogs.perl.org]
The good news is, the YAML double quoted string works the same as in JSON, so if you know that already, you will...
Read more >json.dumps() in Python - GeeksforGeeks
JSON utilizes comma delimited key value pairs contained in double quotes and separated by colons. The body of a JSON file can be...
Read more >Online Quotes - GnuCash
The Finance::Quote software gathers its price data from several Web sites ... gnc-fq-dump yahoo_json M&M.NS [1] 1732 If 'M.NS' is not a typo...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
looks like the if the value has
":"
in it, then the whole value has to be in quotes in order to work with quotesUse ruamel.yaml instead
it is better documented than pyyaml: https://pypi.org/project/ruamel.yaml/