Ashwath Narayanan
Ashwath Narayanan

Reputation: 131

How do I keep a YAML mapping represented as flow mapping {}, not multi-line block mapping?

I have a YAML file a.yaml, which has the following:

allocations:
  hosts:
    - {name: xyz, farm: xyz1}
    - {name: xyz, farm: xyz1}

In my Perl script, I use LoadFile('a.yaml'), convert into a data structure and change the name, and when I dump the data structure, the YAML format is getting changed:

allocations:
  hosts:
    - farm: xyz1
      name: xyz
    - farm: xyz1
      name: xyz

But I want the YAML output to be as same like above a.yaml with the name changed in it:

allocations:
  hosts:
    - {name: xyz1, farm: xyz1}
    - {name: xyz1, farm: xyz1}

Upvotes: 3

Views: 668

Answers (1)

Robert P
Robert P

Reputation: 15978

Sadly, you may have to do this yourself if you must have it in the same format. Having them line by line is still legal yaml, and exactly equivalent: you won't lose any data dumping it that way.

Upvotes: 1

Related Questions