Syntax for empty dictionary in YAML

Short answer: use {}

There are two ways to denote mappings (dictionaries) in yaml; flow mappings and block mappings:

block_mapping:
    name:  foo
    id:    bar
flow_mapping: { name: foo, id: bar }
empty_flow_mapping: {}

The flow mapping style is thus suitable for representing empty mappings.


General technique for answering this type of question, to supplement Betamos’s correct answer: use irb.

$ irb
2.2.0 :001 > require 'yaml'
 => true 
2.2.0 :002 > puts({}.to_yaml)   # original question
--- {}
 => nil 
2.2.0 :003 > puts({ mixed_types: [{}, "string", :symbol, {symbol: "value"}, nil, 3] }.to_yaml)
---
:mixed_types:
- {}
- string
- :symbol
- :symbol: value
- 
- 3
 => nil

I use this whenever I’m unsure how to encode something.