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

v2 and v3 are not the same! #865

Closed
thinkerou opened this issue Jun 10, 2022 · 3 comments
Closed

v2 and v3 are not the same! #865

thinkerou opened this issue Jun 10, 2022 · 3 comments

Comments

@thinkerou
Copy link

thinkerou commented Jun 10, 2022

reproduce simple code: main.go

package main

import (
        "fmt"
        "log"

        "gopkg.in/yaml.v3"
)

var data = `
a: Easy!
b:
  c: 2
  d: [3, 4]
`

type YAML struct {
	Data interface{}
}

func main() {
         data := `
a : Easy!
b:
	c: 2
	d: [3, 4]
	`

        d, err := yaml.Marshal(data)
        if err != nil {
                log.Fatalf("error: %v", err)
        }
        fmt.Printf("--- t dump:\n%s\n\n", string(d))
}

v2 run the result:

➜  go run main.go
--- t dump:
"\na : Easy!\nb:\n\tc: 2\n\td: [3, 4]\n\t"

v3 run the result:

➜  go run main.go
--- t dump:
|4-
    a : Easy!
    b:
    	c: 2
    	d: [3, 4]

why? thanks!

@colega
Copy link

colega commented Aug 11, 2022

Why should they be the same? Both are valid, and it's a new major version.

I think the v3 results is more readable.

@thinkerou
Copy link
Author

Why should they be the same? Both are valid, and it's a new major version.

I think the v3 results is more readable.

I agree more readable, but what's |4-? thanks!

@colega
Copy link

colega commented Aug 11, 2022

See this:

It indicates that it's a block with literal style (|), indented by 4 spaces (4) and the strip chomping indicator (-) that means that the final newline should be stripped.

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

2 participants