125

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:
kellyfj
  • 6,586
  • 12
  • 45
  • 66
maidi
  • 3,219
  • 6
  • 27
  • 55
  • 8
    Based on your comments below this seems like a Twig (or Symfony?) problem, not a YAML problem. The code you've posted is the correct way to specify a null value in YAML (as Robert points out below you can also use `null` or `~`), so the problem is not in your YAML. You should edit your question to include all of the relevant code and add the relevant tags. – Jordan Running Dec 04 '15 at 21:15

3 Answers3

142

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: ~
Robert
  • 19,800
  • 5
  • 55
  • 85
  • 2
    It still gives me the path on the website. I use the yml values in a twig file: `

    {{ '....title.1'|trans }}7 {{ '...title.2'|trans }}2 {{ '...title.3'|trans }}`

    – maidi Dec 04 '15 at 13:45
  • try with `..title[3]` – Robert Dec 04 '15 at 13:51
  • 1
    sadly this does not work. the syntax is correct but I want to "print out" nothing in the translation where title.3 is empty – maidi Dec 04 '15 at 13:55
  • 10
    I'm sorry but I don't understand. The question was about empty field in yaml. If you want to achive something different please edit your question – Robert Dec 04 '15 at 14:01
97

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

title:
    1: String
    2: String2
    3: ''
Alex von Brandenfels
  • 1,608
  • 15
  • 25
  • An empty string is why I came here, didn't actually need NULL - in my case I think Spring boot didn't like empty (at least with comments in line) but did like '' – Matt May 23 '23 at 20:46
36

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 ((
gavenkoa
  • 45,285
  • 19
  • 251
  • 303