Comments (6)
I don't thing this is a bug.
https://yaml.org/type/bool.html
from yaml.
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.
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.
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.
- 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, wherey
andn
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.
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)
- Newline string literals produce invalid marshaling output HOT 2
- Feature request: Find and get information of a Node based on yaml path
- UnmarshalText ignored in arrays HOT 1
- Incompatible with standard `encoding/json` regular expression marshaling HOT 1
- Invalid date-time format during marshalling returns unquoted value. Expecting quoted value. HOT 2
- Marshaling integer values to hexadecimal representation
- v3 skips blank elements in a sequence whereas v2 does not HOT 1
- Different behaviors between this library and standard encoding/json when unmarshal yaml to a struct embedded with other structs HOT 1
- Force marshaler to use multi-line for string with `\n` HOT 1
- Empty `!!null` node fails encoding and causes panic
- Comments rendering issue related to array nodes
- Yaml encoder writing tag of merge node `!!merge` in output
- Custom (Un-)Marshaller on Generic Types ignored
- mining
- Incorrect RC3339 encoding HOT 1
- YAML parsing is not as expected HOT 2
- Yea
- yaml omitempty HOT 2
- `flow` and `inline` structure tags don't work together
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yaml.