Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve node anchors when converting from json -> yaml and restore from json -> yaml. #22

Open
theherk opened this issue Feb 7, 2018 · 0 comments

Comments

@theherk
Copy link
Contributor

theherk commented Feb 7, 2018

Consider the following sample.yaml:

again: &again
  x: several
  y: repeated
  z: values
a:
  again: *again
  k: v
b:
  again: *again
  k: v

This is the output of cat sample.yaml | seria -j | seria -y:

again:
  x: several
  y: repeated
  z: values
a:
  again:
    x: several
    y: repeated
    z: values
  k: v
b:
  again:
    x: several
    y: repeated
    z: values
  k: v

... which is entirely sensible. Some might even say correct. However, wouldn't it be neat if when we got back to yaml the node anchors were back in place?

I'm wondering if you think it would be to hacky to take a switch in the cli to preserve metadata, that stored a known metadata object allowing us to get back. For instance, cat sample.yaml | seria -j --preserve-anchors might look like:

{
  "again": {
    "x": "several",
    "y": "repeated",
    "z": "values"
  },
  "a": {
    "again": {
      "x": "several",
      "y": "repeated",
      "z": "values"
    },
    "k": "v"
  },
  "b": {
    "again": {
      "x": "several",
      "y": "repeated",
      "z": "values"
    },
    "k": "v"
  },
  "_meta": {
    "anchor": {
      "/again": [
        "/a",
        "/b"
      ]
    }
  }
}

Then, back to yaml, cat sample.yaml | seria -j --preserve-anchors | seria -y would output with our original node anchors.

I think that would also allow the preservation of comments.

I have no use for this. But I noticed it trying something unimportant. It is more of a thought experiment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant