YAML support for the Go language

Overview

YAML support for the Go language

PkgGoDev Go 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 install github.com/goccy/go-yaml/cmd/[email protected]

Looking for Sponsors

I'm looking for sponsors this library. This library is being developed as a personal project in my spare time. If you want a quick response or problem resolution when using this library in your project, please register as a sponsor. I will cooperate as much as possible. Of course, this library is developed as an MIT license, so you can use it freely for free.

License

MIT

Issues
  • 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
  • Escape single quotes in single-quoted string

    Escape single quotes in single-quoted string

    According to YAML specification, single quotes must be repeated in a single-quoted scalar.

    https://yaml.org/spec/1.2.2/#732-single-quoted-style

    Fixes goccy/go-yaml#255

    opened by martin-sucha 4
  • Wrong Token offset with CLRF and LF

    Wrong Token offset with CLRF and LF

    Tests to reproduce

    import (
    	"github.com/goccy/go-yaml/lexer"
    	"github.com/stretchr/testify/assert"
    	"testing"
    )
    
    func TestCrlfDemo(t *testing.T) {
    	content := "project:\r\n  version: 1.2.3\r\n"
    	tokens := lexer.Tokenize(content)
    	assert.Len(t, tokens, 5)
    	assert.Equal(t, "1.2.3", tokens[4].Value)
    	assert.Equal(t, 21, tokens[4].Position.Offset)
    }
    
    func TestLfDemo(t *testing.T) {
    	content := "project:\n  version: 1.2.3\n"
    	tokens := lexer.Tokenize(content)
    	assert.Len(t, tokens, 5)
    	assert.Equal(t, "1.2.3", tokens[4].Value)
    	assert.Equal(t, 20, tokens[4].Position.Offset)
    }
    
    === RUN   TestCrlfDemo
        demo_test.go:14: 
            	Error Trace:	demo_test.go:14
            	Error:      	Not equal: 
            	            	expected: 21
            	            	actual  : 26
            	Test:       	TestCrlfDemo
    --- FAIL: TestCrlfDemo (0.00s)
    
    === RUN   TestLfDemo
        demo_test.go:22: 
            	Error Trace:	demo_test.go:22
            	Error:      	Not equal: 
            	            	expected: 20
            	            	actual  : 26
            	Test:       	TestLfDemo
    --- FAIL: TestLfDemo (0.00s)
    

    Notes

    • TestCrlfDemo has the version token at the position 21, but the token stores 26, like the end of the token
    • TestLfDemo has the version token at the position 20, but the token stores 26 again, like the end of the token + 1
    opened by mih-kopylov 0
  • example: add Go fuzz for PathList

    example: add Go fuzz for PathList

    Hello,

    this PR shows a problem with input validation in go-yaml by adding a Go fuzz target. If you are not familiar with Go 1.18 fuzzy tests, see https://tip.golang.org/doc/tutorial/fuzz.

    The main problem is that the code does input validation with a deny list, while for robustness it should do the opposite, use an explicit allow list. See for example https://guides.codepath.org/websecurity/Prefer-whitelisting-over-blacklisting

    This PR is not meant to be merged as-is; it is only a suggestion for how you could make go-yaml more robust.

    opened by marco-m 0
  • Unmarshalling a list of maps fails with

    Unmarshalling a list of maps fails with "unexpected key name"

    I got unexpected key name when I tried to unmarshal the following YAML.

    - "min": 1
      "max": 2
    

    Here is the minimum code to reproduce.

    Code

    package main
    
    import (
    	"github.com/goccy/go-yaml"
    	// "gopkg.in/yaml.v3" // No errors when using this
    )
    
    const yamlBody = `
    - "min": 1
      "max": 2
    `
    
    func main() {
    	var v []struct {
    		Min int
    		Max int
    	}
    
    	err := yaml.Unmarshal([]byte(yamlBody), &v)
    	if err != nil {
    		panic(err)
    	}
    }
    

    Go Playground: https://go.dev/play/p/liMbShEkswO

    Outputs

    panic: [2:10] unexpected key name
    >  2 | - "min": 1
       3 |   "max": 2
    

    Tested versions

    • go 1.17, 1.18
    • goccy/go-yaml: 1.9.5
    bug 
    opened by yamamoto-febc 1
  • partial fix for #298: path.Replace: support anchors

    partial fix for #298: path.Replace: support anchors

    With reference to #298:

    Now the path.Replace* functions do not error out any more, but the returned node is rendered without a newline, thus producing a broken YAML:

    expected: "\na: &a-anchor\n  a1: bar\nb: *a-anchor\n".
    but got   "\na: &a-anchor   a1: bar\nb: *a-anchor\n"
    

    which rendered with the newlines becomes:

    expected:
    "
    a: &a-anchor
      a1: bar
      b: *a-anchor
    "
    
    but got:
    "
    a: &a-anchor   a1: bar
    b: *a-anchor
    "
    

    Am I going in the right direction?

    opened by marco-m 0
  • if YAML contains anchors, path.Replace fails with

    if YAML contains anchors, path.Replace fails with "invalid query"

    Hello,

    consider the following new test case added to TestPath_Replace:

    {
        path: "$.a.a1",
        dst: `
    a: &a-anchor
      a1: foo
    b: *a-anchor
    `,
        src: `bar`,
        expected: `
    a: &a-anchor
      a1: bar
    b: *a-anchor
    `,
    

    it fails with a long stacktrace for the 3 subtests "WithReader", "WithFile" and "WithNode". Here is a shortened version:

    === RUN   TestPath_Replace/$.a.a1/WithNode
        path_test.go:578: failed to replace node by path ( $.a.a1 ):
                github.com/goccy/go-yaml.(*Path).ReplaceWithNode
              - failed to replace:
                github.com/goccy/go-yaml.(*rootNode).replace
              - failed to replace map value:
                github.com/goccy/go-yaml.(*selectorNode).replace
              - failed to replace:
                github.com/goccy/go-yaml.(*selectorNode).replaceMapValue
              - expected node type is map or map value. but got Anchor:
                github.com/goccy/go-yaml.(*selectorNode).replace
              - invalid query:
                github.com/goccy/go-yaml.init
    

    I have a partial fix, but the problem is that somehow some newlines are not printed. See PR #299.

    opened by marco-m 0
  • Example of roundtrip with node and processing (modification)

    Example of roundtrip with node and processing (modification)

    Hello, thanks for this library!

    If I use yaml.MapSlice I am able to easily perform a roundtrip YAML -> Go -> YAML, modify some elements and write them back in the same order, which is very important for any kind of YAML processing to be validated by a human.

    Now I would like to go one step further: my input YAML contains anchors and aliases, so I cannot just use yaml.MapSlice to keep the order, since the YAML anchors are expanded by the decoding, so that if I were to write back the YAML, also without any modification, I would still write back all the anchors expanded, which is not what I want.

    So I looked at ast.Node, but I am not sure how to use it; by looking at the API, I could not find a way to go back from node to YAML. I might be missing something obvious ?

    Probably related: #285

    opened by marco-m-pix4d 1
Releases(v1.9.5)
  • 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
Go-yaml - Yaml parsing Toolkit For Golang

go-yaml 介绍 gopkg.in/yaml.v3 已经是个非常好用的包,但是在实际开发中总有类型转换带来的麻烦,go-yaml只是在它的基础上,简单的一层

xiaowu 4 Jan 13, 2022
Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.

koanf (pronounced conf; a play on the Japanese Koan) is a library for reading configuration from different sources in different formats in Go applicat

Kailash Nadh 1k Jun 26, 2022
Golang Configuration tool that support YAML, JSON, TOML, Shell Environment

Configor Golang Configuration tool that support YAML, JSON, TOML, Shell Environment (Supports Go 1.10+) Usage package main import ( "fmt" "github.c

Jinzhu 1.4k Jun 27, 2022
Generic templating tool with support of JSON, YAML and TOML data

gotempl Small binary used to generate files from Go Templates and data files. The following formats are supported: JSON YAML TOML Usage usage: gotempl

Link Society 7 Jun 15, 2022
JSON or YAML configuration wrapper with convenient access methods.

Config Package config provides convenient access methods to configuration stored as JSON or YAML. This is a fork of the original version. This version

Oleg Lebedev 250 May 5, 2022
Library providing routines to merge and validate JSON, YAML and/or TOML files

CONFLATE Library providing routines to merge and validate JSON, YAML, TOML files and/or structs (godoc) Typical use case: Make your application config

Andy 25 May 5, 2022
A better way to marshal and unmarshal YAML in Golang

YAML marshaling and unmarshaling support for Go Introduction A wrapper around go-yaml designed to enable a better way of handling YAML when marshaling

Sam Ghods 919 Jun 22, 2022
create a bootable disk image from Docker image or a yaml config

docker2boot docker2boot creates a bootable disk from either a Docker image or a config yaml file Features status dns Y cloud-init Y network Y ssh TODO

Bin Chen 6 Dec 21, 2021
It syncronizes the configuration described in a YAML file against your GitHub Organization

It syncronizes the configuration described in a YAML file against your GitHub Organization. Combined with a CI system, it can be used to implement GitOps for GitHub.

Carlos Tadeu Panato Junior 6 Jul 19, 2021
Golang library for reading properties from configuration files in JSON and YAML format or from environment variables.

go-config Golang library for reading properties from configuration files in JSON and YAML format or from environment variables. Usage Create config in

null 3 Feb 22, 2022
Golang config.yaml loader

Description goconfig is a configuration library designed using the following pri

null 2 May 31, 2022
Tmpl - A tool to apply variables from cli, env, JSON/TOML/YAML files to templates

tmpl allows to apply variables from JSON/TOML/YAML files, environment variables or CLI arguments to template files using Golang text/template and functions from the Sprig project.

krako 1 May 30, 2022
SmartYAML - Go package to handle YAML

SmartYAML - Go package to handle YAML The smartyaml is a go package to handle parsed YAML files more confortable. This package is not a parser, it use

Péter Deák 0 Feb 25, 2022
VINYL Inscribes Nettlesome YAML Legibly

VINYL Inscribes Nettlesome YAML Legibly VINYL formats yaml files into a canonical format retaining comments and setting the indentation by default to

Jesse Hathaway 1 Jan 18, 2022
Go-config - Config parser for go that supports environment vars and multiple yaml files

go-multiconfig This package is able to parse yaml config files. It supports gett

Dimitris Tassopoulos 1 Jun 23, 2022
HCL is the HashiCorp configuration language.

HCL HCL is a toolkit for creating structured configuration languages that are both human- and machine-friendly, for use with command-line tools. Altho

HashiCorp 4.1k Jun 24, 2022
Go library for the TOML language

go-toml Go library for the TOML format. This library supports TOML version v1.0.0-rc.3 Features Go-toml provides the following features for using data

Thomas Pelletier 1.3k Jun 29, 2022
Tom's Obvious, Minimal Language

TOML Tom's Obvious, Minimal Language. By Tom Preston-Werner, Pradyun Gedam, et al. This repository contains the in-development version of the TOML spe

TOML 17.1k Jun 25, 2022