Skip to content

Problem when converting yaml to json on merge tags #38

@FALLAI-Denis

Description

@FALLAI-Denis

Describe the bug

It seems to me that there is a problem when converting a yaml document to json on the handling of merge tags:

  • the merger does not operate
  • an object level named "<<" is added

To Reproduce

Steps to reproduce the behavior:

  1. Create this yaml file
anchor: &default
  first: 1
  second: 2
  other : the default
alias: *default
merge: 
  <<: *default
  other: not the default
  1. rename file extension to json

  2. See error

{
  "anchor": {
    "first": 1,
    "second": 2,
    "other": "the default"
  },
  "alias": {
    "first": 1,
    "second": 2,
    "other": "the default"
  },
  "merge": {
    "<<": {
      "first": 1,
      "second": 2,
      "other": "the default"
    },
    "other": "not the default"
  }
}

Expected behavior

The content of the anchor must be merged with the other properties without adding an object level.

{
  "anchor": {
    "first": 1,
    "second": 2,
    "other": "the default"
  },
  "alias": {
    "first": 1,
    "second": 2,
    "other": "the default"
  },
  "merge": {
    "first": 1,
    "second": 2,
    "other": "not the default"
  }
}

(please complete the following information):

  • OS: Windows 10
  • Version 21H1
  • Vscode version 1.56.2
  • Extension version 1.7.0

Additional context

Apply to sample at https://yaml.org/type/merge.html

---
- &CENTER { x: 1, y: 2 }
- &LEFT { x: 0, y: 2 }
- &BIG { r: 10 }
- &SMALL { r: 1 }

# All the following maps are equal:

- # Explicit keys
  x: 1
  y: 2
  r: 10
  label: center/big

- # Merge one map
  << : *CENTER
  r: 10
  label: center/big

- # Merge multiple maps
  << : [ *CENTER, *BIG ]
  label: center/big

- # Override
  << : [ *BIG, *LEFT, *SMALL ]
  x: 1
  label: center/big

Result (reformated to highlight the differences):

[
  {"x": 1, "y": 2},
  {"x": 0, "y": 2},
  {"r": 10},
  {"r": 1},

  { "x": 1, "y": 2,"r": 10, "label": "center/big"},

  {"<<": {"x": 1, "y": 2}, "r": 10, "label": "center/big"},

  {"<<": [{"x": 1, "y": 2}, {"r": 10}], "label": "center/big"},

  {"<<": [{"r": 10}, {"x": 0, "y": 2}, {"r": 1}], "x": 1, "label": "center/big"}

]

https://jsonformatter.org/yaml-to-json works as expected (and as expected in the YAML specification):

[
    {"x": 1, "y": 2},
    {"x": 0, "y": 2},
    {"r": 10},
    {"r": 1},

    {"x": 1, "y": 2, "r": 10, "label": "center/big"},

    {"x": 1, "y": 2, "r": 10, "label": "center/big"},

    {"x": 1, "y": 2, "r": 10, "label": "center/big"},

    {"r": 10, "x": 1, "y": 2, "label": "center/big"}
]

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions