question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[help-needed]: Is there a way to parse and dump a yaml file and preserving the format of array/sequence?

See original GitHub issue

I 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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rlidwkacommented, Jul 13, 2021

@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

1reaction
puzrincommented, Jul 4, 2021

May be flowLevel

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found