YAML support for the Go language

Overview

YAML support for the Go language

PkgGoDev CircleCI codecov Go Report Card

Why a new library?

As of this writing, there already exists a de facto standard library for YAML processing for Go: https://github.com/go-yaml/yaml. However we feel that some features are lacking, namely:

  • Pretty format for error notifications
  • Direct manipulation of YAML abstract syntax tree
  • Support for Anchor and Alias when marshaling
  • Allow referencing elements declared in another file via anchors

Features

  • Pretty format for error notifications
  • Supports Scanner or Lexer or Parser as public API
  • Supports Anchor and Alias to Marshaler
  • Allow referencing elements declared in another file via anchors
  • Extract value or AST by YAMLPath ( YAMLPath is like a JSONPath )

Installation

go get -u github.com/goccy/go-yaml

Synopsis

1. Simple Encode/Decode

Has an interface like go-yaml/yaml using reflect

var v struct {
	A int
	B string
}
v.A = 1
v.B = "hello"
bytes, err := yaml.Marshal(v)
if err != nil {
	//...
}
fmt.Println(string(bytes)) // "a: 1\nb: hello\n"
	yml := `
%YAML 1.2
---
a: 1
b: c
`
var v struct {
	A int
	B string
}
if err := yaml.Unmarshal([]byte(yml), &v); err != nil {
	//...
}

To control marshal/unmarshal behavior, you can use the yaml tag.

	yml := `---
foo: 1
bar: c
`
var v struct {
	A int    `yaml:"foo"`
	B string `yaml:"bar"`
}
if err := yaml.Unmarshal([]byte(yml), &v); err != nil {
	//...
}

For convenience, we also accept the json tag. Note that not all options from the json tag will have significance when parsing YAML documents. If both tags exist, yaml tag will take precedence.

	yml := `---
foo: 1
bar: c
`
var v struct {
	A int    `json:"foo"`
	B string `json:"bar"`
}
if err := yaml.Unmarshal([]byte(yml), &v); err != nil {
	//...
}

For custom marshal/unmarshaling, implement either Bytes or Interface variant of marshaler/unmarshaler. The difference is that while BytesMarshaler/BytesUnmarshaler behaves like encoding/json and InterfaceMarshaler/InterfaceUnmarshaler behaves like gopkg.in/yaml.v2.

Semantically both are the same, but they differ in performance. Because indentation matters in YAML, you cannot simply accept a valid YAML fragment from a Marshaler, and expect it to work when it is attached to the parent container's serialized form. Therefore when we receive use the BytesMarshaler, which returns []byte, we must decode it once to figure out how to make it work in the given context. If you use the InterfaceMarshaler, we can skip the decoding.

If you are repeatedly marshaling complex objects, the latter is always better performance wise. But if you are, for example, just providing a choice between a config file format that is read only once, the former is probably easier to code.

2. Reference elements declared in another file

testdata directory contains anchor.yml file:

├── testdata
   └── anchor.yml

And anchor.yml is defined as follows:

a: &a
  b: 1
  c: hello

Then, if yaml.ReferenceDirs("testdata") option is passed to yaml.Decoder, Decoder tries to find the anchor definition from YAML files the under testdata directory.

buf := bytes.NewBufferString("a: *a\n")
dec := yaml.NewDecoder(buf, yaml.ReferenceDirs("testdata"))
var v struct {
	A struct {
		B int
		C string
	}
}
if err := dec.Decode(&v); err != nil {
	//...
}
fmt.Printf("%+v\n", v) // {A:{B:1 C:hello}}

3. Encode with Anchor and Alias

3.1. Explicitly declared Anchor name and Alias name

If you want to use anchor or alias, you can define it as a struct tag.

type T struct {
  A int
  B string
}
var v struct {
  C *T `yaml:"c,anchor=x"`
  D *T `yaml:"d,alias=x"`
}
v.C = &T{A: 1, B: "hello"}
v.D = v.C
bytes, err := yaml.Marshal(v)
if err != nil {
  panic(err)
}
fmt.Println(string(bytes))
/*
c: &x
  a: 1
  b: hello
d: *x
*/

3.2. Implicitly declared Anchor and Alias names

If you do not explicitly declare the anchor name, the default behavior is to use the equivalent of strings.ToLower($FieldName) as the name of the anchor.

If you do not explicitly declare the alias name AND the value is a pointer to another element, we look up the anchor name by finding out which anchor field the value is assigned to by looking up its pointer address.

type T struct {
	I int
	S string
}
var v struct {
	A *T `yaml:"a,anchor"`
	B *T `yaml:"b,anchor"`
	C *T `yaml:"c,alias"`
	D *T `yaml:"d,alias"`
}
v.A = &T{I: 1, S: "hello"}
v.B = &T{I: 2, S: "world"}
v.C = v.A // C has same pointer address to A
v.D = v.B // D has same pointer address to B
bytes, err := yaml.Marshal(v)
if err != nil {
	//...
}
fmt.Println(string(bytes)) 
/*
a: &a
  i: 1
  s: hello
b: &b
  i: 2
  s: world
c: *a
d: *b
*/

3.3 MergeKey and Alias

Merge key and alias ( <<: *alias ) can be used by embedding a structure with the inline,alias tag.

type Person struct {
	*Person `yaml:",omitempty,inline,alias"` // embed Person type for default value
	Name    string `yaml:",omitempty"`
	Age     int    `yaml:",omitempty"`
}
defaultPerson := &Person{
	Name: "John Smith",
	Age:  20,
}
people := []*Person{
	{
		Person: defaultPerson, // assign default value
		Name:   "Ken",         // override Name property
		Age:    10,            // override Age property
	},
	{
		Person: defaultPerson, // assign default value only
	},
}
var doc struct {
	Default *Person   `yaml:"default,anchor"`
	People  []*Person `yaml:"people"`
}
doc.Default = defaultPerson
doc.People = people
bytes, err := yaml.Marshal(doc)
if err != nil {
	//...
}
fmt.Println(string(bytes))
/*
default: &default
  name: John Smith
  age: 20
people:
- <<: *default
  name: Ken
  age: 10
- <<: *default
*/

4. Pretty Formatted Errors

Error values produced during parsing have two extra features over regular error values.

First, by default, they contain extra information on the location of the error from the source YAML document, to make it easier to find the error location.

Second, the error messages can optionally be colorized.

If you would like to control exactly how the output looks like, consider using yaml.FormatError, which accepts two boolean values to control turning these features on or off.

5. Use YAMLPath

yml := `
store:
  book:
    - author: john
      price: 10
    - author: ken
      price: 12
  bicycle:
    color: red
    price: 19.95
`
path, err := yaml.PathString("$.store.book[*].author")
if err != nil {
  //...
}
var authors []string
if err := path.Read(strings.NewReader(yml), &authors); err != nil {
  //...
}
fmt.Println(authors)
// [john ken]

5.1 Print customized error with YAML source code

package main

import (
  "fmt"

  "github.com/goccy/go-yaml"
)

func main() {
  yml := `
a: 1
b: "hello"
`
  var v struct {
    A int
    B string
  }
  if err := yaml.Unmarshal([]byte(yml), &v); err != nil {
    panic(err)
  }
  if v.A != 2 {
    // output error with YAML source
    path, err := yaml.PathString("$.a")
    if err != nil {
      panic(err)
    }
    source, err := path.AnnotateSource([]byte(yml), true)
    if err != nil {
      panic(err)
    }
    fmt.Printf("a value expected 2 but actual %d:\n%s\n", v.A, string(source))
  }
}

output result is the following:

Tools

ycat

print yaml file with color

ycat

Installation

go get -u github.com/goccy/go-yaml/cmd/ycat

License

MIT

Comments
  • Unable to interact with a field where its name containing a dot character

    Unable to interact with a field where its name containing a dot character

    Hi, thank you for your nice library. We are using your lib at our OSS https://github.com/pipe-cd/pipe and it works really nice.

    As the title of this issue, we are facing a problem while parsing the path $.data.envoy-config.yaml because it is containing a dot character. In Kubernetes context, it is normal to specify a field with a file name including its extension so the . will be included. It makes go-yaml parses the path in a wrong way.

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: envoy
    data:
      envoy-config.yaml: |-
        admin:
          address:
            socket_address:
              address: 0.0.0.0
              port_value: 9095
    

    So do we have any way to deal with this case? Can we use \ to escape the dot or something like that?

    Thank you.

    opened by nghialv 9
  • Cannot parse yaml file

    Cannot parse yaml file

    My config file cannot be parser. It complains on a unexpected key at 16,1. Removing the empty line before the "masters:" key, makes Unmarshall parse it.

    bad.yml.txt

    The yamlv.2 package parses it correctly, though.

    opened by RafaelGCPP 9
  • Add Marshaler / Unmarshaler interface compatible with encoding/json

    Add Marshaler / Unmarshaler interface compatible with encoding/json

    Supported both interfaces

    Marshaler

    • MarshalYAML() ([]byte, error)
    • MarshalYAML() (interface{}, error)

    Unmarshaler

    • UnmarshalYAML(func(interface{})error) error
    • UnmarshalYAML([]byte) error
    opened by goccy 9
  • Multiline block fix

    Multiline block fix

    Introduced the option ForceBlockIfMultiline, which allows multiline strings containing "special YAML characters" to be represented in prettified blocks, instead of being quoted forcefully.

    The main reason for this PR existence is the desire to have more prettified YAML code.

    E.g. let's use the following map element:

    myMap := map[string]interface{}{"v": "# comment\nname: hello\npassword: hello123\nspecial: \":ghost:\"\ntext: |\n  nested multiline!"}
    

    When encoded "normally", the result is:

    v: "# comment\nname: hello\npassword: hello123\nspecial: \":ghost:\"\ntext: |\n  nested multiline!"
    

    When encoded with the ForceBlockIfMultiline option, the result is:

    v: |-
      # comment
      name: hello
      password: hello123
      special: ":ghost:"
      text: |
        nested multiline!
    
    opened by cmaster11 7
  • API to change error behavior

    API to change error behavior

    ドキュメントを読んでたら以下を見たのですが

    errors.ColoredErr = false
    

    yamlパッケージで色々処理を書いているのにerrorsのグローバル変数をいじってエラー表示方法を変えるのがちょっと微妙だなー、と思います。

    1. ユーザー的には errorsがpublicである必要性がない
    2. 必要ならerrorsじゃなくてyamlパッケージに対して処理を依頼するほうがユーザー的には自然
    3. そもそも、エラーを表示する方法を変えるだけなので、yaml側で変更するより、ユーザー側のコードで制御するほうが自然なのでは

    と感じました。

    今のAPIだとこうですが、

    import (
       "github.com/goccy/go-yaml"
       "github.com/goccy/go-yaml/errors" // errors.ColoredErrのためだけに必要
    )
    
    if err := yaml.Unmarshal(...); err != nil {
       errors.ColoredErr = false
       fmt.Println(err)
    }
    

    こんな感じにしてしまえばよいかと

    import (
       "github.com/goccy/go-yaml"
        // go-yaml/errorsは go-yaml/internal/errors に隠蔽してしまう
    )
    
    if err := yaml.Unmarshal(...); err != nil {
       yaml.PrettyPrintError(err) // or yaml.PrettyPrintError(err, boolColoredErr, boolIncludeSource)
    }
    

    とかにするとユーザー側としては

    1. そもそもerrorsパッケージを外部から利用する必要もなければ、internalだから利用もできない
    2. errorsではなくyamlパッケージにPrettyPrintを依頼する形になり自然
    3. 明示的に yaml.PrettyPrintError()を呼ぶことによって、ユーザー側で出力を変更できるし、グローバル変数にも依存しない

    という形にできるかと思います。

    よければPR書きます

    opened by lestrrat 7
  • Comments in YAML break annotated source

    Comments in YAML break annotated source

    Or at least it seems like the comments are causing issue.

    Here's a minimal reproduction:

    package main
    
    import (
    	"fmt"
    
    	"github.com/goccy/go-yaml"
    )
    
    // yamlSrc returns the annotated raw source at pathStr
    func yamlSrc(raw []byte, pathStr string) (msg string, err error) {
    	path, err := yaml.PathString(pathStr)
    	if err != nil {
    		return
    	}
    	source, err := path.AnnotateSource(raw, true)
    	if err != nil {
    		return
    	}
    	msg = "\n" + string(source)
    	return
    }
    
    func main() {
    	src := (`# This is my document
    doc:
      # It has nice inline comments
      inline:
        # And value comments
        - value
        - other value
        # It isn't super consistent
        - last value
      other:
        - value
      # This comment should be line 12
      line:
        # And below should be line 15
        - fifteen
        - sixteen
      done: true  # Line 17
    	`)
    	msg, err := yamlSrc([]byte(src), "$.doc.line[0]")
    	if err != nil {
    		panic(err)
    	}
    	fmt.Println(msg)
    
    	// Output expected (ish):
    	// 13 |     line:
    	// 14 |     # And below should be line 15
    	// 15 |     - fifteen
    	//          ^
    	// 16 |     - sixteen
    	// 17 |   done: true  # Line 17
    	//
    	// Actual output:
    	// 13 |     line:    - fifteen
    	//            ^
    	// 16 |     - sixteen
    	// 17 |   done: true  # Line 17
    	// 18 |
    }
    

    And here's a screenshot of the output on OS X go 1.17 github.com/goccy/go-yaml v1.9.3: image

    bug 
    opened by shakefu 5
  • Parsing AST with comments breaks output

    Parsing AST with comments breaks output

    With version v1.8.9 the following program:

    package main
    
    import (
    	"os"
    
    	"github.com/goccy/go-yaml/parser"
    )
    
    func main() {
    	input := []byte(`
    x:
      - a
      #- b
      - c
      #- d
    `)
    	f, err := parser.ParseBytes(input, parser.ParseComments)
    	if err != nil {
    		panic(err)
    	}
    	os.Stdout.Write([]byte(f.String()))
    }
    

    prints the following unexpected output:

    x:
      - a
      - - c
    #- d
    

    I would expect it to print the input unmodified

    x:
      - a
      #- b
      - c
      #- d
    
    
    opened by martin-sucha 5
  • Fix to give back error when path not found

    Fix to give back error when path not found

    Fixes https://github.com/goccy/go-yaml/issues/193

    This is happening because Path.Read() assumes it's going to have a non-nil Node if no error returned. But it could give back a nil Node even if no error was given.

    I little poked around the codebase and most of the callers of Path.FilterFile() assume the same does.

    It would be great if you could give me any feedback.

    opened by nakabonne 5
  • explicit-key indicator

    explicit-key indicator "?" is treated as a directive

    https://github.com/goccy/go-yaml/blob/master/scanner/scanner.go#L670

    In all the yaml variants, ? indicates the start of a key in a mapping. In this scanner, ? is treated as a directive.

    YAML 1.1 Example YAML 1.2 Example

    I would fix this, but I don't sufficiently grok the scanner to know how to push it into "the next thing is a mapping key" mode.

    bug 
    opened by jeffalder 5
  • Add disallowUnknownField Option

    Add disallowUnknownField Option

    opened by kitagry 5
  • Fix large literals type inference on 32 bits

    Fix large literals type inference on 32 bits

    Some tests are failing because some large literal integers are meant to be stored on 64 bits, but are stored on 32 on 32 bits architectures. This causes the value to overflow:

    # github.com/goccy/go-yaml_test [github.com/goccy/go-yaml.test]
    ./decode_test.go:92:32: cannot use -9223372036854775808 (untyped int constant) as int value in map literal (overflows)
    ./decode_test.go:112:24: cannot use 4294967296 (untyped int constant) as int value in map literal (overflows)
    ./encode_test.go:68:24: cannot use 4294967296 (untyped int constant) as int value in map literal (overflows)
    

    This commit fixes this issue by using explicit int64 typing.

    opened by jrisc 4
  • scanner: Find quoted token from context

    scanner: Find quoted token from context

    Closes #301

    To resolve an issue with quoted map keys not correctly parsing, this PR changes how it progresses after scanning a quote token.

    The old behaviour was:

    1. scanner reaches a :
    2. pull the characters out of the current scan context buffer and turn it into the map key token
    3. set the previous indent column to the beginning of the buffer So next time it gets to another key in the map, it'll check whether the indent was the same.

    When scanning a quote:

    1. Scan from the beginning to the end of the quote sequence
    2. Add a token, send back to the lexer, and reset the scan context In this scenario, it reaches the :, but nothing is in the scan context buffer because it just went ahead and added the quote token. The previous indent column doesn't get reset, so when it gets to the next map key it thinks the indent increased, which is invalid yaml.

    The new behaviour is essentially to not reset the context after scanning a quote, and when reaching a : check the context tokens, and if it's a quote set the previous indent column to that

    opened by braydonk 6
  • comments are not properly preserved following folded/literal string

    comments are not properly preserved following folded/literal string

    If a comment follows a field using folded or literal style strings, the first line of the comment is lost, for example (https://play.golang.com/p/mN4v86pSwP8 https://play.golang.com/p/xHeGkd9bxDu https://play.golang.com/p/uzQ8WGzA4gs https://play.golang.com/p/wDYKVpHPdSL)

    document:
      - key1:
          key2: |
            Some text.
    
      # This is an important comment explaining key3.
      # Second line of comment.
      - key3:
          value: 1
    

    becomes

    document:
      - key1:
          key2: |
            Some text.
      # Second line of comment.
      - key3:
          value: 1
    

    This does not happen with quoted or unquoted strings (https://play.golang.com/p/dc2RCZmRrIR https://play.golang.com/p/tjBLgB8OaG9).

    This appears to be due to incorrect association of comments with nodes in the AST during parsing.

    The YAML document above has the following AST comment associations (https://play.golang.com/p/3WtBBjARGXF)

    comment: # This is an important comment explaining key3.
    associated node:
          key2: |
            Some text.
    
    comment: # Second line of comment.
    associated node:
    document:
      - key1:
          key2: |
            Some text.
      # Second line of comment.
      - key3:
          value: 1
    

    Where we can see that the first line of the comments is incorrectly associated with the key2 node, but is not emitted, and the second line is correctly associated with the first element of the sequence via the ValueComments slice.

    opened by efd6 0
  • There is a bad performance hit when upgrading to >= 1.9.2

    There is a bad performance hit when upgrading to >= 1.9.2

    We found out that after upgrading to 1.9.6 there was a big hit in reading ~~ 270 files. After doing some version comparisions, the problem seems to be introduced in v1.9.3.

    ❯ go get -u github.com/goccy/[email protected]
    go: downgraded github.com/goccy/go-yaml v1.9.3 => v1.8.10
    ❯ go build
    ❯ time ./go-ftw check -d ../coreruleset/tests
    ftw/check: checked 276 files, everything looks good!
    ./go-ftw check -d ../coreruleset/tests  0.50s user 0.09s system 60% cpu 0.961 total
    ❯ go get -u github.com/goccy/[email protected]
    go: upgraded github.com/goccy/go-yaml v1.8.10 => v1.9.3
    ❯ go build
    ❯ time ./go-ftw check -d ../coreruleset/tests
    ftw/check: checked 276 files, everything looks good!
    ./go-ftw check -d ../coreruleset/tests  32.89s user 2.49s system 359% cpu 9.845 total
    ❯ go get -u github.com/goccy/[email protected]
    go: downgraded github.com/goccy/go-yaml v1.9.3 => v1.9.1
    ❯ go build
    ❯ time ./go-ftw check -d ../coreruleset/tests
    ftw/check: checked 276 files, everything looks good!
    ./go-ftw check -d ../coreruleset/tests  0.51s user 0.09s system 64% cpu 0.936 total
    ❯ go get -u github.com/goccy/[email protected]
    go: upgraded github.com/goccy/go-yaml v1.9.1 => v1.9.2
    ❯ time ./go-ftw check -d ../coreruleset/tests
    ftw/check: checked 276 files, everything looks good!
    ./go-ftw check -d ../coreruleset/tests  0.52s user 0.09s system 104% cpu 0.581 total
    ❯ go get -u github.com/goccy/[email protected]
    go: upgraded github.com/goccy/go-yaml v1.9.2 => v1.9.3
    ❯ go build
    ❯ time ./go-ftw check -d ../coreruleset/tests
    ftw/check: checked 276 files, everything looks good!
    ./go-ftw check -d ../coreruleset/tests  32.47s user 2.41s system 358% cpu 9.724 total
    

    See https://github.com/coreruleset/go-ftw/issues/115. Right now we downgraded to pre 1.9.3, but probably we want to check out what the problem is and write some benchmarks.

    opened by fzipi 2
  • go-yaml does not properly set indent for nodes obtained from in-line JSON

    go-yaml does not properly set indent for nodes obtained from in-line JSON

    The following program shows that nodes derived from in-line JSON do not properly set their indent, resulting in corrupted output.

    https://play.golang.com/p/jxYRN0uVB9J

    This returns the following output:

    processors:
      - date:
          if: "ctx.event?.timezone == null && ctx._temp_?.raw_date != null"
          target_field: "@timestamp"
          on_failure:
        ppend":
        eld": "error.message", "value": "{{{ _ingest.on_failure_message }}}"}}]
    

    Note that the data is correctly deserialised as can be seen when the data is passed through an any and re-serialised, https://play.golang.com/p/6cCkHpw2MYr.

    opened by efd6 1
  • go-yaml fails to parse valid yaml with quoted key names

    go-yaml fails to parse valid yaml with quoted key names

    The following yaml is valid (confirmed by YAMLint and consumption with gopkg.in/yaml.v3.

    processors:
      - script:
          params:
            "ctx._temp_.cisco.message_id":
              target: event.action
              map:
                "430001": intrusion-detected
                "430002": connection-started
                "430003": connection-finished
                "430004": file-detected
                "430005": malware-detected
            "dns.question.type":
              map:
                "a host address": A
                "ip6 address": AAAA
                "text strings": TXT
                "a domain name pointer": PTR
                "an authoritative name server": NS
                "the canonical name for an alias": CNAME
                "marks the start of a zone of authority": SOA
                "mail exchange": MX
                "server selection": SRV
            "dns.response_code":
              map:
                "non-existent domain": NXDOMAIN
                "server failure": SERVFAIL
                "query refused": REFUSED
                "no error": NOERROR
    

    This fails to parse with the following error (reproducer https://play.golang.com/p/i-745AaaTDc ):

    2009/11/10 23:00:00 [8:23] unexpected key name
           5 |         "ctx._temp_.cisco.message_id":
           6 |           target: event.action
           7 |           map:
        >  8 |             "430001": intrusion-detected
           9 |             "430002": connection-started
                                     ^
          10 |             "430003": connection-finished
          11 |             "430004": file-detected
          12 |             "430005": malware-detected
          13 |         
    

    Successful parse with gopkg.in/yaml.v3 here https://play.golang.com/p/AtASNYxRPY4.

    opened by efd6 1
Releases(v1.9.6)
  • v1.9.6(Oct 26, 2022)

    What's Changed

    • UTF-8 Support by @nervo in https://github.com/goccy/go-yaml/pull/294
    • Update golang.org/x/sys by @nervo in https://github.com/goccy/go-yaml/pull/289
    • fix incorrect const type by @chanxuehong in https://github.com/goccy/go-yaml/pull/284
    • Update Go version in CI by @goccy in https://github.com/goccy/go-yaml/pull/295
    • yaml: typeError implements PrettyPrinter interface by @braydonk in https://github.com/goccy/go-yaml/pull/280
    • path tests: add missing keys to struct literals by @marco-m in https://github.com/goccy/go-yaml/pull/300
    • Introduce MapKeyNode interface to limit node types for map key by @itchyny in https://github.com/goccy/go-yaml/pull/312
    • Fix large literals type inference on 32 bits by @jrisc in https://github.com/goccy/go-yaml/pull/293
    • fix: insert a separator between each encoded document by @zoncoen in https://github.com/goccy/go-yaml/pull/318
    • Handle unmarshall unknown aliases by @nervo in https://github.com/goccy/go-yaml/pull/317
    • Quote strings with special characters in flow mode. by @igorpeshansky in https://github.com/goccy/go-yaml/pull/270

    New Contributors

    • @chanxuehong made their first contribution in https://github.com/goccy/go-yaml/pull/284
    • @braydonk made their first contribution in https://github.com/goccy/go-yaml/pull/280
    • @marco-m made their first contribution in https://github.com/goccy/go-yaml/pull/300
    • @itchyny made their first contribution in https://github.com/goccy/go-yaml/pull/312
    • @jrisc made their first contribution in https://github.com/goccy/go-yaml/pull/293
    • @igorpeshansky made their first contribution in https://github.com/goccy/go-yaml/pull/270

    Full Changelog: https://github.com/goccy/go-yaml/compare/v1.9.5...v1.9.6

    Source code(tar.gz)
    Source code(zip)
  • v1.9.5(Jan 12, 2022)

    What's Changed

    New Features

    • Add UseSingleQuote option by @vikstrous2 in https://github.com/goccy/go-yaml/pull/265

    Fixed bugs

    • Escape single quotes in single-quoted string by @martin-sucha in https://github.com/goccy/go-yaml/pull/256
    • Fix minor typo in decodeInit error by @hasheddan in https://github.com/goccy/go-yaml/pull/264
    • Preserve defaults while decoding nested structs by @Al2Klimov in https://github.com/goccy/go-yaml/pull/260
    • Handle empty sequence entries by @tnthornton in https://github.com/goccy/go-yaml/pull/275
    • Fix encoding of sequence with multiline string by @goccy in https://github.com/goccy/go-yaml/pull/276
    • Fix encoding of BytesMarshaler type by @goccy in https://github.com/goccy/go-yaml/pull/277
    • Fix indentState logic for multi-line value by @goccy in https://github.com/goccy/go-yaml/pull/278

    New Contributors

    • @martin-sucha made their first contribution in https://github.com/goccy/go-yaml/pull/256
    • @hasheddan made their first contribution in https://github.com/goccy/go-yaml/pull/264
    • @Al2Klimov made their first contribution in https://github.com/goccy/go-yaml/pull/260
    • @tnthornton made their first contribution in https://github.com/goccy/go-yaml/pull/275

    Full Changelog: https://github.com/goccy/go-yaml/compare/v1.9.4...v1.9.5

    Source code(tar.gz)
    Source code(zip)
  • v1.9.4(Oct 12, 2021)

    What's Changed

    • Keep prev/next reference between tokens containing comments when filtering comment tokens by @goccy in https://github.com/goccy/go-yaml/pull/257
    • Supports escaping reserved keywords in PathBuilder by @goccy in https://github.com/goccy/go-yaml/pull/258

    Full Changelog: https://github.com/goccy/go-yaml/compare/v1.9.3...v1.9.4

    Source code(tar.gz)
    Source code(zip)
  • v1.9.3(Sep 7, 2021)

    New Features

    • Support encoding and decoding time.Duration fields ( #246 )
    • Allow reserved characters for key name in YAMLPath ( #251 )
    • Support getting YAMLPath from ast.Node ( #252 )
    • Support CommentToMap option ( #253 )

    Fix bugs

    • Fix encoding nested sequences with yaml.IndentSequence ( #241 )
    • Fix error reporting on inline structs in strict mode ( #244, #245 )
    • Fix encoding of large floats ( #247 )

    Improve workflow

    • Migrate CI from CircleCI to GitHub Action ( #249 )
    • Add workflow for ycat ( #250 )
    Source code(tar.gz)
    Source code(zip)
  • v1.9.2(Jul 26, 2021)

    Support WithComment option ( #238 )

    yaml.WithComment is a option for encoding with comment. The position where you want to add a comment is represented by YAMLPath, and it is the key of yaml.CommentMap. Also, you can select Head comment or Line comment as the comment type.

    Source code(tar.gz)
    Source code(zip)
  • v1.9.1(Jul 20, 2021)

  • v1.9.0(Jul 19, 2021)

    New features

    • Support encoding of comment node ( #233 )
    • Support yaml.NodeToValue(ast.Node, interface{}, ...DecodeOption) error ( #236 )
      • Can convert a AST node to a value directly

    Fix decoder for comment

    • Fix parsing of literal with comment ( #234 )

    Rename API ( #235 )

    • Rename MarshalWithContext to MarshalContext
    • Rename UnmarshalWithContext to UnmarshalContext
    Source code(tar.gz)
    Source code(zip)
  • v1.8.10(Jul 2, 2021)

    Fixed bugs

    • Fix searching anchor by alias name ( #212 )
    • Fixing Issue 186, scanner should account for newline characters when processing multi-line text. Without this source annotations line/column number (for this and all subsequent tokens) is inconsistent with plain text editors. e.g. https://github.com/goccy/go-yaml/issues/186. This addresses the issue specifically for single and double quote text only. ( #210 )
    • Add error for unterminated flow mapping node ( #213 )
    • Handle missing required field validation ( #221 )
    • Nicely format unexpected node type errors ( #229 )
    • Support to encode map which has defined type key ( #231 )

    New features

    • Support sequence indentation by EncodeOption ( #232 )
    Source code(tar.gz)
    Source code(zip)
  • v1.8.9(Mar 1, 2021)

    Fix bugs

    • Fix origin buffer for DocumentHeader and DocumentEnd and Directive
    • Fix origin buffer for anchor value
    • Fix syntax error about map value
    • Fix parsing MergeKey ('<<') characters
    • Fix encoding of float value
    • Fix incorrect column annotation when single or double quotes are used

    New feature

    • Support to encode/decode of ast.Node directly
    Source code(tar.gz)
    Source code(zip)
  • v1.8.7(Feb 2, 2021)

  • v1.7.19(Jul 15, 2020)

  • v1.7.17(Jun 23, 2020)

  • v1.7.16(Jun 20, 2020)

  • v1.7.15(Jun 17, 2020)

  • v1.7.14(Jun 16, 2020)

  • v1.7.13(Jun 16, 2020)

  • v1.7.12(Jun 15, 2020)

  • v1.7.11(Jun 15, 2020)

  • v1.7.10(Jun 15, 2020)

Owner
Masaaki Goshima
Masaaki Goshima
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.

dasel Dasel (short for data-selector) allows you to query and modify data structures using selector strings. Comparable to jq / yq, but supports JSON,

Tom Wright 3.8k Nov 21, 2022
Generate High Level Cloud Architecture diagrams using YAML syntax.

A commandline tool that generate High Level microservice & serverless Architecture diagrams using a declarative syntax defined in a YAML file.

Luca Sepe 554 Nov 23, 2022
Tool for shell commands execution, visualization and alerting. Configured with a simple YAML file.

Sampler. Visualization for any shell command. Sampler is a tool for shell commands execution, visualization and alerting. Configured with a simple YAM

Alexander Lukyanchikov 11k Nov 22, 2022
YAML Incremental Digger.

yd YAML Incremental Digger. Installation $ go install github.com/skanehira/[email protected] Usage All of first, you can read yaml file as following. $ yd fil

skanehira 15 Feb 19, 2022
An alternative syntax to generate YAML (or JSON) from commandline

yo An alternative syntax to generate YAML (or JSON) from commandline. The ultimate commanline YAML (or JSON) generator! ... I'm kidding of course! but

Luca Sepe 10 Jul 30, 2022
🔄 A command-line utility to export Protocol Buffers (proto) files to YAML, and JSON

proto2yaml ?? A command-line utility to export Protocol Buffers (proto) files to YAML, and JSON. Currently supported exports are for: Packages Service

Kristof Kowalski 9 Nov 10, 2022
CLI for SendGrid, which helps in managing SSO users, can install and update users from yaml config

Sendgrid API This script is needed to add new users to SendGrid as SSO teammates. Previously, all users were manually added and manually migrating the

ANNA 4 Jul 20, 2022
yq lets you read YAML files easily on the terminal. You can find key/values easily

yq yq lets you read YAML files easily on the terminal. You can find key/values easily. Motivation Reading yaml configurations for k8s file becomes ard

Farhan 3 Nov 2, 2021
yq is a portable command-line YAML processor

yq a lightweight and portable command-line YAML processor. yq uses jq like syntax but works with yaml files as well as json. It doesn't yet support ev

Mike Farah 6.9k Nov 29, 2022
📝 Easily format yaml files on terminal or your editor

YAMLFMT A simple and extensible yaml formatter. Installation go install github.com/UltiRequiem/[email protected] Make sure your $PATH includes the $GOPAT

Eliaz Bobadilla 27 Oct 31, 2022
Utility CLI to convert Spring Boot Yaml configuration into external configuration

boot-config-export Utility CLI to convert Spring Boot Yaml configuration into external configuration (as environment variables). The variables are tra

Lucian 0 Nov 17, 2021
A CLI tool which loads data from yaml files into the Google Cloud Spanner tables

splanter A CLI tool which loads data from yaml files into the Google Cloud Spanner tables (mainly for the development).

Yuki Ito 15 Oct 27, 2022
Use the command to convert arbitrary formats to Go Struct (including json, toml, yaml, etc.)

go2struct-tool Use the command to convert arbitrary formats to Go Struct (including json, toml, yaml, etc.) Installation Run the following command und

Afeyer 1 Dec 16, 2021
Flag is a simple but powerful command line option parsing library for Go support infinite level subcommand

Flag Flag is a simple but powerful commandline flag parsing library for Go. Documentation Documentation can be found at Godoc Supported features bool

null 123 Sep 26, 2022
Fully featured Go (golang) command line option parser with built-in auto-completion support.

go-getoptions Go option parser inspired on the flexibility of Perl’s GetOpt::Long. Table of Contents Quick overview Examples Simple script Program wit

David Gamba 46 Sep 26, 2022
Advanced ANSI style & color support for your terminal applications

termenv lets you safely use advanced styling options on the terminal. It gathers information about the terminal environment in terms of its ANSI & col

Christian Muehlhaeuser 1.2k Nov 22, 2022
A golang library for building interactive prompts with full support for windows and posix terminals.

Survey A library for building interactive prompts on terminals supporting ANSI escape sequences. package main import ( "fmt" "github.com/Alec

Alec Aivazis 3.4k Nov 23, 2022
CLI to support with downloading and compiling terraform providers for Mac with M1 chip

m1-terraform-provider-helper A CLI to help with managing the installation and compilation of terraform providers when running a new M1 Mac. Motivation

kreuzwerker GmbH 244 Nov 17, 2022
Declarative CLI Version manager. Support Lazy Install and Sharable configuration mechanism named Registry. Switch versions seamlessly

aqua Declarative CLI Version manager. Support Lazy Install and Sharable configuration mechanism named Registry. Switch versions seamlessly. Index Slid

Shunsuke Suzuki 230 Nov 30, 2022