go-yaml / yaml

YAML support for the Go language.
Other
6.84k stars 1.04k forks source link

Add new node to yaml file #452

Open RaynDol opened 5 years ago

RaynDol commented 5 years ago

HI,

I've the following yaml file and I need to insert to it a new object (json) and to keep the structure the same

For example

lets say I’ve this yml file

version: 1
type: verbose
kind : bfr

# my list of applications
applications:
  - name: app1
    kind: nodejs
    path: app1
    exec:
      platforms: k8s
      builder: test

This is the json object which I need to insert

[

    {
        "comment: "Second app",
        "name": "app2",
        "kind": "golang",
        "path": "app2",
        "exec": {
            "platforms": "dockerh",
            "builder": "test"
        }
    }
]

I need to add it to the yml file after the first application, (applications is array of application)

version: 1
type: verbose
kind : bfr

# my list of applications
applications:

#  First app
  - name: app1
    kind: nodejs
    path: app1
    exec:
      platforms: k8s
      builder: test

# Second app
  - name: app2
    kind: golang
    path: app2
    exec:
      platforms: dockerh
      builder: test

is it possible to add to the yaml file the new json object with the node capability ? is there some example which I can use as reference?

RaynDol commented 5 years ago

@niemeyer, I've created the following question on stack overflow , without any answer yet. it would be great if you could have a look and answer there, that others can also benefit from it, since I think V3 provide some killer features.

https://stackoverflow.com/questions/55674853/modify-existing-yaml-file-and-add-new-data-and-comments