Replies: 4 comments 12 replies
-
Hello, I really don't know what to think about this. My use-case is to generate a jsonschema that will be used to validate YAML file in VSCode (via this plugin). I just added the missing json tags in my code, and it produces the exact same jsonchema as before (https://github.com/CGI-FR/PIMO/pull/142/files#diff-79ca10368c383e5ed5c7d8885fe1f4c2758b5ae4afd3feaf629e3a348b69b054) so I think it's fine. I don't see why you should keep the yaml tags support, for now. I hope i'm right ! :) |
Beta Was this translation helpful? Give feedback.
-
In my usecase, I need to parse yaml config to go-struct. No need for json tags or json conversion at all. Used previous version of jsonschema to generate |
Beta Was this translation helpful? Give feedback.
-
My main argument applicable to our code would rest on that idea that code should be self documenting as much as possible. Using I do see the point around the use case where you are parsing (or writing) both yaml and json for the same struct. If you have that use case, then it does make sense to use one set of any customisations for both. Its a shame to see some of the bugs and behaviours pointed out with go-yaml. Given the blog was written in 2014, and gopkg.in/yaml.v3 has come out much more recently, have the issues been pointed out to the maintainers so they could defend or change them with the v3 breaking changes? I want to offer 1 critique of the examples shown in the blog. They do illustrate the json/yaml behaviour differences, but in my opinion, code that avoids any issues from the behaviour, would be better regardless of whether yaml/json unmarshalling had that discrepancy or not. type DateOfBirth struct {
Time *time.Time // Pointer to a time.Time struct.
}
func (dob *DateOfBirth) UnmarshalJSON(b []byte) error { ... } I would be asking why do you want time to be type DateOfBirth time.Time
func (dob *DateOfBirth) UnmarshalJSON(b []byte) error { ... } which incidentally, won't have any problems unmarshalling null from yaml. |
Beta Was this translation helpful? Give feedback.
-
I've been using this library to generate JSON Schemas to eventually create Jsonnet libraries. However running this against Prometheus didn't give me the usual result, turns out it only supports the YAML tags and don't seem willing to change it. One of the arguments is that they support YAML anchors. I'm not involved in the prometheus project and figure I might run into similar walls elsewhere so dropping a message here. Perhaps you can suggest a workaround for me? |
Beta Was this translation helpful? Give feedback.
-
In this PR #23 we took steps to remove support for YAML tags. Previous versions of jsonschema did have support for using
yaml
ifjson
was not available, or if a configuration option was enabled forcing priority of theyaml
tag.Ultimately, the decision to remove support for YAML was based on the potential for confusion. JSON Schema isn't really optimised for the YAML use-case, which has a more complex syntax. If you ever tried to parse a JSON file created based on a JSON Schema generated using YAML tags, you would get unexpected results.
If you need to deal with YAML, our recommended approach is to first convert to JSON and then parse using the
json
tags. The invopop/yaml repo will handle this for you.37 votes ·
Beta Was this translation helpful? Give feedback.
All reactions