Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

sql: do not marshal strings containing JSON as a string in convert #710

Merged
merged 1 commit into from
May 14, 2019

Conversation

erizocosmico
Copy link
Contributor

Fixes #709

When a string containing JSON (e.g. {"a": 1, "b": true}) is passed
to JSON.Convert, it only did json.Marshal, so it was marshalled as
a string (e.g. "{\"a\":1,\"b\":true}"), which made it impossible
to use a string with JSON_EXTRACT, which would only receive the
string.

Now, JSON.Convert does a first check for strings. If it can be
unmarshalled into JSON, then that JSON is marshalled and returned.
Otherwise, it's a string and marshalled as such.

Signed-off-by: Miguel Molina miguel@erizocosmi.co

Fixes src-d#709

When a string containing JSON (e.g. `{"a": 1, "b": true}`) is passed
to JSON.Convert, it only did `json.Marshal`, so it was marshalled as
a string (e.g. `"{\"a\":1,\"b\":true}"`), which made it impossible
to use a string with JSON_EXTRACT, which would only receive the
string.

Now, JSON.Convert does a first check for strings. If it can be
unmarshalled into JSON, then that JSON is marshalled and returned.
Otherwise, it's a string and marshalled as such.

Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
@erizocosmico erizocosmico requested a review from a team May 14, 2019 07:59
@ajnavarro ajnavarro merged commit b3c5fda into src-d:master May 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSON_EXTRACT cannot cast JSON string
3 participants