Skip to content

Assignment for nested keys is broken for keys following referenced parent key #1746

Open
@EmilyGraceSeville7cf

Description

@EmilyGraceSeville7cf

Describe the bug
= assignment is broken for nested keys following referenced one-level up property related to them.

Version of yq: 4.34.2
Operating system: Linux 22.04 Ubuntu
Installed via: sudo apt install yq

Input Yaml
Concise yaml document(s) (as simple as possible to show the bug, please keep it to 10 lines or less)
data1.yml:

    {
        "first": {
            "type": "string"
        },
        "second": {
            "type": "string"
        },
        "referenced": {
            "type": "string"
        },
        "third": {
            "type": "string"
        },
        "fourth": {
            "type": "string"
        }
    }

Command
The command you ran:

yq -P -o json '.[].type = .referenced'

Actual behavior

{
  "first": {
    "type": {
      "type": "string"
    }
  },
  "second": {
    "type": {
      "type": "string"
    }
  },
  "referenced": {
    "type": {
      "type": "string"
    }
  },
  "third": {
    "type": {
      "type": {
        "type": "string"
      }
    }
  },
  "fourth": {
    "type": {
      "type": {
        "type": "string"
      }
    }
  }
}

Expected behavior

{
  "first": {
    "type": {
      "type": "string"
    }
  },
  "second": {
    "type": {
      "type": "string"
    }
  },
  "referenced": {
    "type": {
      "type": "string"
    }
  },
  "third": {
    "type": {
      "type": "string"
    }
  },
  "fourth": {
    "type": {
      "type": "string"
    }
  }
}

type keys after referenced key are assigned incorrectly. I've compared output with jq and it works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions