Comments (6)
The example above prints {10 0} instead of {10 20}
from yaml.
Confusingly, it looks like this is part of YAML: http://yaml.org/type/bool.html. From the linked page, we see that any key or value that matches the following pattern is considered a boolean:
y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF
This is reflected in this project here, where the key is changed to the string "true"
. It actually continues marshaling the value too, so if your struct had a Y int
json:"true"`` or True int
field, its value would be 20.
To get around this, you can quote the y
in your YAML. Both single and double quotes seemed to work fine.
from yaml.
Sorry to butt in - I hit this issue as well. The above-mentioned "boolean pattern" is defined only in yaml-1.1 - and is marked as a draft. The current specification (yaml 1.2: http://www.yaml.org/spec/1.2/spec.html) has none of this - and the overview explicitly states that this has been removed (along with other "implicit typing rules"). BTW, current YAML parsers in other languages (e.g., Python) don't do this, either. IMO, this "feature" should be removed.
from yaml.
👍
@lwalen, thanks for the workaround - it does help. Still, things break if we have to parse externally provided files (e.g., ones generated by humans, pythons or other non-Go creatures) rather than yaml files specially crafted to work around this issue
If the old behavior is desirable for backward compatibility (unlikely), the old behavior can be preserved through an option. Considering that the latest YAML spec (1.2, see @snarfbeest comment) does not require/allow for this behavior, I would propose the default to be off (i.e., compliant with the latest spec); if we really must keep this behavior by default, it will still be better to have the proper parsing to be available even if we have to request it explicitly.
I do love this package otherwise!
from yaml.
Unfortunately, this behavior is controlled by the go-yaml package that this package depends on - this package doesn't parse out what a boolean is, it just trusts go-yaml to tell it which values are booleans and uses that derived information. If you'd like go-yaml to expose an option to change its behavior, you can chime in on this PR here go-yaml/yaml#222 ... if they expose the option I'd be happy to utilize it in my library as well.
from yaml.
Closing for now since there is no action unless go-yaml exposes an option.
from yaml.
Related Issues (20)
- Unmarshal() is case insensitive to object attribute names
- Int overflow on 32 bits arches HOT 1
- Unmarshaling is incorrect, particularly around numbers.
- Newline and carriage return control characters characters are not escaped when converting YAML to JSON HOT 1
- http://ghodss.com/2014/the-right-way-to-handle-yaml-in-golang/ returns 404 HOT 3
- Unmarshal does not work if a field name differs from related annotation name HOT 1
- yamltojson got wrong output format
- yaml.v3 support
- return yaml as same as json
- export convertToJSONableObject
- unable to convert zero prepended integer from YAML file to YAML object using “yaml.Unmarshal”
- Add support for UnmarshalStrict
- In yaml.v3 how to achieve ordered map?
- 【bug】Capital change to lowercase HOT 1
- Is this repo still in maintaining state? HOT 3
- How about cutting a new release? HOT 2
- Keys like "yes" and "on" are read as true HOT 4
- Does the string wrap automatically? HOT 1
- ⚡ Is anyone maintaining the project ? HOT 3
- 🚚 New fork available at invopop/yaml HOT 6
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.