You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the encoding/json package in Go provides functionality for encoding and decoding JSON data, but it does not support JSON Schema. JSON Schema is a powerful tool for validating the structure of JSON data, and it's widely used in many applications.
Proposal
I propose to add JSON Schema support to the encoding/json package. This would allow developers to validate JSON data against a schema, and it could also provide a way to automatically generate Go types from a JSON Schema.
Benefits
Adding JSON Schema support would have several benefits:
Data validation: JSON Schema provides a clear and standardized way to validate JSON data. This can help prevent bugs and improve the reliability of applications.
Code generation: With JSON Schema support, we could potentially generate Go types from a schema. This could save developers time and reduce the risk of errors.
Interoperability: JSON Schema is a widely used standard. By supporting it in Go, we can improve the interoperability of Go applications with other systems.
Implementation
The implementation details would need to be discussed further. One possible approach could be to integrate an existing open-source JSON Schema library into the encoding/json package
The new functionality could look something like this:
// Load a JSON Schema from a fileschema, err:=json.LoadSchema("schema.json")
iferr!=nil {
// handle error
}
// Validate JSON data against the schemaerr=schema.Validate(jsonData)
iferr!=nil {
// handle validation error
}
// Unmarshal Go types from the schematypes, err:=schema.Unmarshal(jsonData)
iferr!=nil {
// handle error
}
This would make it much easier to work with JSON data in Go, especially in applications that need to handle complex or variable data structures.
Impact
Adding JSON Schema support to the encoding/json package would increase its complexity and maintenance cost. However, I believe the benefits would outweigh the costs. JSON Schema is a widely used standard, and supporting it in Go would make the language more attractive to developers who work with JSON data.
I'm looking forward to hearing your thoughts on this proposal.
Thank you.
The text was updated successfully, but these errors were encountered:
It's not clear to me that this is something that needs to live inside the standard library, as opposed to something that is first developed externally and once it has proven it's utility and worth, then be considered for adoption. In your example, all of the schema parsing and validation logic occurs separate from the unmarshal, which calls into question whether this needs to be part of the "json" package versus say a "jsonschema" package.
Background
Currently, the
encoding/json
package in Go provides functionality for encoding and decoding JSON data, but it does not support JSON Schema. JSON Schema is a powerful tool for validating the structure of JSON data, and it's widely used in many applications.Proposal
I propose to add JSON Schema support to the
encoding/json
package. This would allow developers to validate JSON data against a schema, and it could also provide a way to automatically generate Go types from a JSON Schema.Benefits
Adding JSON Schema support would have several benefits:
Data validation: JSON Schema provides a clear and standardized way to validate JSON data. This can help prevent bugs and improve the reliability of applications.
Code generation: With JSON Schema support, we could potentially generate Go types from a schema. This could save developers time and reduce the risk of errors.
Interoperability: JSON Schema is a widely used standard. By supporting it in Go, we can improve the interoperability of Go applications with other systems.
Implementation
The implementation details would need to be discussed further. One possible approach could be to integrate an existing open-source JSON Schema library into the
encoding/json
packageThe new functionality could look something like this:
This would make it much easier to work with JSON data in Go, especially in applications that need to handle complex or variable data structures.
Impact
Adding JSON Schema support to the encoding/json package would increase its complexity and maintenance cost. However, I believe the benefits would outweigh the costs. JSON Schema is a widely used standard, and supporting it in Go would make the language more attractive to developers who work with JSON data.
I'm looking forward to hearing your thoughts on this proposal.
Thank you.
The text was updated successfully, but these errors were encountered: