Duplicate key in YAML configuaration file

18,548

Solution 1

Your YAML is syntactically invalid, but I am assuming it actually looks like this:

key1:
  key2: "value"

key1:
  key2:
    key3: "value2"

Your error is that key1 is used two times as mapping key in the root node. This is illegal as per YAML spec:

The content of a mapping node is an unordered set of key: value node pairs, with the restriction that each of the keys is unique.

The solution is to make all keys of the same mapping unique:

key11:
  key2: "value"

key12:
  key2:
    key3: "value2"

Solution 2

I too faced the same issue. Then it struck on me! The answer is simple. From

mapping:
  refresh:
    schedule:
      frequency:
        milli: 86400000
mapping:
  refresh:
    schedule:
      initial:
        delay:
          ms: 30000

to

mapping:
  refresh:
    schedule:
      frequency:
        milli: 86400000
      initial:
        delay:
          ms: 30000
Share:
18,548
Admin
Author by

Admin

Updated on June 05, 2022

Comments

  • Admin
    Admin almost 2 years

    Have the following in YAML-

    key1
      key2: "value"
    
    key1
      key2
        key3: "value2"
    

    Get exception duplicate key key1. Caused by: org.yaml.snakeyaml.parser.ParserException: while parsing MappingNode

    Trying various combinations but unable to parse it correctly.

    Could someone please help or guide here.

    Thanks

  • Admin
    Admin over 6 years
    cannot make te keys unique due to some requirement constraints