How do I export data into yaml with mapping?
Those two are semantically the same thing. The only difference is that the {} format is more compact.
See the output in these two links.

Regardless, the second argument to the dump method lets you configure the verbosity of arrays. See Writing YAML Files.