X Tutup
The Wayback Machine - https://web.archive.org/web/20201017055018/https://github.com/json-iterator/go/issues/486
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

Make compatibility mode to unmarshal json coming from weakly type languages #486

Open
masterada opened this issue Aug 26, 2020 · 0 comments
Open

Comments

@masterada
Copy link
Contributor

@masterada masterada commented Aug 26, 2020

We have been using jsoniter for a while now in our microservices, being able to specify the json tag is awesome, so thanks for the great library!

I would like an option during unmarshalling, which allows more flexibility for types. What I have in mind, is a Compatiblity option, which allows the followings (the list might not be complete):

  • Make empty values interchangable:
    • null, "", [], {}, 0, false should be acceptable value for any type
  • Allow unmarshalling common boolean representations into a boolean value
    • "true", "false", 0, 1, "0", "1"
  • Accept string representation of numeric values
    • allow "0", "0.5", as value for numeric types
    • when string type found and unmarshal fails, try unmarshal after unqoute
  • Allow unmarshalling object into array, as long as all keys in the object are string representations of an integer
    • eg: {"0": "a", "2": "b"} should be unmarshalled to []string

We use go in all our projects, except the public gateway, because php handles not perfectly formed jsons better. However, we are reaching the limits of php (mainly mainteinability issues). We would like to migrate to go, but we need a more flexible json unmarshaller to handle inputs coming from js.

What is you opinion about this? Can this be part of json-iterator, or is this something you belive is out of the project's scope?

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

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.
X Tutup