Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JSONv2 when production ready #15

Open
zamicol opened this issue Apr 5, 2023 · 2 comments
Open

Use JSONv2 when production ready #15

zamicol opened this issue Apr 5, 2023 · 2 comments

Comments

@zamicol
Copy link
Contributor

zamicol commented Apr 5, 2023

Instead of making various issues for various JSON concerns. I'm going to use this issue to track any concerns with JSON.

Coze needs strictly defined JSON capabilities. Some of these capabilities are not provided by the standard
Go library, or misbehaves under certain circumstances. Currently, there are no known 3rd party libraries that we consider suitable for Coze. Our hope is that we can use JSONv2 when production ready and that will solve any JSON concerns.

A new JSON library should minimally include these characteristics in addition to
the existing behavior of the standard library:

  • Duplicate fields should error.
  • Preserve order of JSON fields.
  • Invalid UTF-8 should error.
  • JSON should not be HTML escaped. (For example when containing the characters &, <,>. and while not adding an additional new line as the standard library currently does.)

Three of the larger obstacles:

To resolve these obstacles, Coze implemented orderedmap, its own custom JSON unmarshaler, and a "checkDuplicate" helper function.

A search of other Go JSON issues that may be relevant to Coze:
https://github.com/golang/go/issues?q=is%3Aissue+is%3Aopen+encoding%2Fjson+in%3Atitle

JSONv2

See https://pkg.go.dev/github.com/go-json-experiment/json
There are other best practices in JSONv2.

@peterbourgon
Copy link

peterbourgon commented Apr 9, 2023

JSON is defined by a spec which doesn't guarantee any of the characteristics you list here. If you want to rely on them you're no longer accepting JSON input, you're accepting something else, based on JSON, but with additional constraints. The JSONv2 library doesn't really solve anything, it encodes stuff in a certain way, but that encoded form isn't guaranteed by JSON and can't be relied upon when decoding input.

@zamicol
Copy link
Contributor Author

zamicol commented Apr 10, 2023

I think JSON spec concerns are addressed on the other issue and that's probably the better place for discussion on Coze's relationship to the JSON spec: #10 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants