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

JSON_EXTRACT cannot cast JSON string #709

Closed
kuba-- opened this issue May 13, 2019 · 0 comments · Fixed by #710
Closed

JSON_EXTRACT cannot cast JSON string #709

kuba-- opened this issue May 13, 2019 · 0 comments · Fixed by #710
Assignees
Labels
bug Something isn't working

Comments

@kuba--
Copy link
Contributor

kuba-- commented May 13, 2019

With or without a CAST JSON_EXTRACT doesn't accept JSON as a string, e.g.:
you should be able to call JSON_EXTRACT('[1, 2, 3]', '$.[0]') but it returns a NULL.
For '$' argument it returns the first parameter as a string, otherwise NULL.

@kuba-- kuba-- added the bug Something isn't working label May 13, 2019
@erizocosmico erizocosmico self-assigned this May 14, 2019
erizocosmico added a commit to erizocosmico/go-mysql-server that referenced this issue May 14, 2019
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>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants