Giter VIP home page Giter VIP logo

Comments (6)

stavros-k avatar stavros-k commented on July 18, 2024

I don't thing this is a bug.
https://yaml.org/type/bool.html

from yaml.

TLINDEN avatar TLINDEN commented on July 18, 2024

I see.

I understand it for values, as in enable: yes which should become enable: true. But why would anyone do this with keys? Doesn't make any sense to me.

So now I have to add a function to my code to remove the quotes in such cases, because I use YAML only for pretty printing of arbitrary structs.

😠

from yaml.

stavros-k avatar stavros-k commented on July 18, 2024

I've seen a fair share of weird things people do in yaml. I do agree that keys shouldn't be treated as values. I haven't read up on the yaml spec to the fullest, so I'm not sure if this is "by spec" or not. I just stumbled upon your issue by "accident". Hope someone more well versed in the spec can chime in

from yaml.

TLINDEN avatar TLINDEN commented on July 18, 2024

It's worse than just adding quotes, it also removes keys from the struct:

	type Punkt struct {
		y, YES, yes int
	}

	po := Punkt{4, 6, 8}
	by, _ := yaml.Marshal(po)
	fmt.Println(string(by))
	
	fmt.Printf("Punkt: %#v", po)

Prints:

"yes": 6

Punkt: main.Punkt{y:4, YES:6, yes:8}

from yaml.

perlpunk avatar perlpunk commented on July 18, 2024
  1. YAML is a data serialization language. Mapping keys can be strings, numbers, null, booleans and even mappings or sequences as well. Not every language can implement this, but a boolean as a mapping key is totally valid in YAML, even if you don't see a use case for it
    2.. go-yaml implements YAML 1.1, where y and n are booleans. in YAML 1.2 the list of scalars that are recognized as booleans has been reduced drastically, along with some other changes. More and more YAML libraries are slowly picking this up, but it is still not very well known by users.

from yaml.

TLINDEN avatar TLINDEN commented on July 18, 2024

Thanks for the clarification. I already put a workaround into my module, since I am only using YAML as data dumper/visualization tool.

from yaml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.