maidi
maidi

Reputation: 3459

Empty field in yaml

I want to leave a value in my .yaml field empty, because in another translation there has to be something but not in this one. Just leaving it empty prints out the path of the value (...title.3).

title:
    1: String
    2: String2
    3:

Upvotes: 132

Views: 186594

Answers (3)

gavenkoa
gavenkoa

Reputation: 48743

According to YAML v1.2 spec:

10.3.2. Tag Resolution

Regular expression         Resolved to tag
null | Null | NULL | ~     tag:yaml.org,2002:null
/* Empty */                tag:yaml.org,2002:null

So putting null or ~ or omitting value produces the same result: tag:yaml.org,2002:null:

parent:
  key1:               # empty so "null", # is a comment!
  key2: ~             # also "null"
  key3: null          # "null" explicitly ))
  key4: !!null "null" # for the funs of "secondary tag handle: !!"
  key5: "null"        # sorry, it is a string or !!str if you like ((

Upvotes: 44

Alex von Brandenfels
Alex von Brandenfels

Reputation: 1856

If you want an empty string, rather than a null value, you can use two single quotes.

title:
    1: String
    2: String2
    3: ''

Upvotes: 108

Robert
Robert

Reputation: 20286

You can use ~ or null.

You should read documentation of YAML and you can read Symfony Yaml Format as well

title:
    1: String
    2: String2
    3: ~

Upvotes: 150

Related Questions