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

Attempt parsing raw string before calling to_json #806

Merged

Conversation

matthewmcgarvey
Copy link
Member

Connected to luckyframework/lucky#1661

When we call params.nested(:user) we get back a Hash(String, String). The String value is a stringified version of the json object which the current implementation would not parse correctly. This new overload attempts to parse the raw string value before calling .to_json on it.

This does change behavior:

JSON::Any.adapter.parse("true") #=> "true" : JSON::Any (before)
JSON::Any.adapter.parse("true") #=> true : JSON::Any (after)

JSON::Any.adapter.parse("1") #=> "1" : JSON::Any (before)
JSON::Any.adapter.parse("1") #=> 1 : JSON::Any (after)

JSON::Any.adapter.parse("{\"foo\":\"bar\"}") #=> "{\"foo\":\"bar\"}" : JSON::Any (before)
JSON::Any.adapter.parse("{\"foo\":\"bar\"}") #=> {"foo" => "bar"} : JSON::Any

I believe these tradeoffs are acceptable because most JSON::Any columns aren't doing scalar values anyways and this new way is more true to intention especially being constrained by how Lucky::Params works.

Copy link
Member

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me!

@matthewmcgarvey matthewmcgarvey merged commit 58de417 into luckyframework:master Feb 2, 2022
@matthewmcgarvey matthewmcgarvey deleted the json-parse-strings branch February 2, 2022 02:50
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

Successfully merging this pull request may close these issues.

None yet

2 participants