0

I have this snippet in a longer YAML:

config:
  operations: !!map

IntelliJ marks the !! as error (expected key-val pair or array item), probably a false positive.
I wanted to understand more about it so I opened YAML specifications but I am still not sure about its use.

Is it used to specify a type or something else?

Pitto
  • 8,229
  • 3
  • 42
  • 51
  • 2
    Does this answer your question? [What does a single exclamation mark do in YAML?](https://stackoverflow.com/questions/9664113/what-does-a-single-exclamation-mark-do-in-yaml) – Lei Yang Apr 08 '22 at 08:36
  • It mentions is but it is not specifically related to it... I did not find the answer you suggest because the title specifically mentions "single" :) – Pitto Apr 08 '22 at 08:51
  • 1
    yeah. they may have different meanings. ^_^ – Lei Yang Apr 08 '22 at 08:52

1 Answers1

0

On the document you linked, it says that !! is a Secondary Handle or a Core type (Generic Mapping)

Secondary Handle

The secondary tag handle is written as “!!”. This allows using a compact notation for a single “secondary” name space. By default, the prefix associated with this handle is “tag:yaml.org,2002:”.

Further example usages on https://yaml.org/refcard.html is as follows

...
'!foo' : Primary (by convention, means a local "!foo" tag).
'!!foo' : Secondary (by convention, means "tag:yaml.org,2002:foo").
...
Core types: # Default automatic tags.
'!!map' : { Hash table, dictionary, mapping }
'!!seq' : { List, array, tuple, vector, sequence }
'!!str' : Unicode string

More types:
'!!set' : {cherries, plums, apples }
'!!omap': [ one: 1, two: 2 ]

In your example, it defines that operations is a map that can have other values. Can see more info here Generic Mapping

Block style: !!map
  Clark : Evans
  Ingy  : döt Net
  Oren  : Ben-Kiki

Flow style: !!map { Clark: Evans, Ingy: döt Net, Oren: Ben-Kiki }
khakiout
  • 2,372
  • 25
  • 32
  • 1
    why need? i don't see anything wrong if you remove `!!map` in the block style. – Lei Yang Apr 08 '22 at 08:44
  • 1
    @LeiYang It's generally not needed. YAML specifies that mappings get assigned this tag implicitly *but* you can theoretically define a YAML schema that would assign a different tag implicitly, and could then use `!!map` to prevent that. Nobody does this because YAML is used a bit differently from how it was originally envisioned. – flyx Apr 08 '22 at 09:36