Syntax for empty dictionary in YAML

前端 未结 2 861
没有蜡笔的小新
没有蜡笔的小新 2021-02-04 22:46

How do I denote an empty dictionary in YAML? I.e. it should be semantically equivalent to the empty json-object {}.

2条回答
  •  温柔的废话
    2021-02-04 23:40

    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.

提交回复
热议问题