0

If I have a JSON doc like this:

{
  "foo": "bar",
  "foo:oo": "bar2"
}

I can access the property "foo" with:

SELECT col->"$.foo" // Outputs "bar"

However, if I try to access the property named "foo:oo" like so:

SELECT col->"$.foo:oo" // Should output "bar2", but triggers an error

I get the following error:

Invalid JSON path expression. The error is around character position 8.

How can I access a property that has a semicolon?

1 Answer 1

2
SELECT col->"$foo:oo" // Should output "bar2", but triggers an error

You are missing a dot:

SELECT col->"$.foo:oo"

I got this to work in an online mysql environment:

CREATE TABLE t1 (sentence JSON);
INSERT INTO t1 VALUES('{"foo": "bar", "foo:oo": "bar2"}');    
SELECT sentence ->> '$."foo:oo"' FROM t1;
Sign up to request clarification or add additional context in comments.

3 Comments

I'm sorry. It was a typo on my post. I am using the dot. Edited.
It works on jsonpath.com. Have you tried the bracket notation $.['foo:oo']? It's probably confused by ":". Note: I would also try double quotation if single quotes are not working.
Updated my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.