jsonpath icon indicating copy to clipboard operation
jsonpath copied to clipboard

Single quotes are not supported

Open rob-chkk opened this issue 3 years ago • 1 comments

The JSONPath standard supports single-quotes for bracket notation (see here) but they fail with a syntax error:

m := map[string]interface{}{
  "field": map[string]interface{}{
    "sub-field": "hello",
  },
}
value, err := jsonpath.Get("$.field['sub-field']", m) 
// err is incorrectly set to `could not parse string: invalid syntax`

// the following case works correctly:
value, err := jsonpath.Get("$.field[\"sub-field\"]", m) 
// err is nil, value is "hello"

Instead I'd expect this to work correctly.

rob-chkk avatar Jun 08 '22 20:06 rob-chkk

This seems to be an issue of the Gval library, which is using the text/scanner go library, which does not use single quotes to indicate strings and as such throws an error. In go, single quotes indicate single characters only. As such, it's unlikely that text/scanner will be changed to accommodate this issue and should probably be solved in Gval.

JanHoefelmeyer avatar Jul 07 '23 12:07 JanHoefelmeyer