[help-needed]: Is there a way to parse and dump a yaml file and preserving the format of array/sequence?
See original GitHub issueI would like to know if it’s possible to pass options to the parser
and/or the dump
methods to preserve the format of the arrays and sequence as it is originally in the file. Right now , when running the dump, I get the following transformation:
node_version: ["12", "14"]
to
node_version:
- "12"
- "14"
Example: https://github.com/oscard0m/octoherd-script-replace-all-repository-topics/pull/14/files
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Python YAML – Read, Write, Parse YAML - PYnative
Python YAML Dump – Write into YAML File. Let's see how to write Python objects into YAML format file. Use the PyYAML module's...
Read more >How to preserve format with yaml dump in python3
I want to change only the attribute anotherName from the following yaml file with python. test.yaml:
Read more >YAML: The Missing Battery in Python
In this tutorial, you'll learn how to work with YAML in Python using the available third-party libraries, with a focus on PyYAML.
Read more >Reading and Writing YAML to a File in Python - Stack Abuse
In this tutorial, we're going to learn how to use the YAML library in Python 3. YAML stands for Yet Another Markup Language....
Read more >How to Load, Read, and Write YAML - Python Land
Learn how to open, parse, and read YAML with Python. ... Writing (or dumping) YAML to a file; Convert YAML to JSON using...
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 Free
Top 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
@oscard0m , yes and no.
node_version: ["12", "14"]
is parsed into JS object{ node_version: [ 12, 14 ] }
, which does not have the information about formatting, as you can see yourself.However, you can override yaml types to make
node_version: ["12", "14"]
to parse to whatever you like, and store format information somewhere there.Look at custom types, might find a few ideas here: https://github.com/nodeca/js-yaml/issues/613#issuecomment-814319894
May be
flowLevel