Escaping Characters in Bigquery json_extract() function

Viewed 6088

when using Google's BigQuery, there's a function that can extract elements from json strings using jsonPath. For example:

SELECT JSON_EXTRACT(data,"$.key.value") AS feature FROM tablename

when the json key itself contains a dot,{"key.value":"value"} It's not clear how to escape that properly.

this jsonpath message board question says that jsonpath itself supports this format

@Test 
public void path_with_bracket_notation() throws Exception { 
    String json = "{\"foo.bar\": {\"key\": \"value\"}}"; 

    Assert.assertEquals("value", JsonPath.read(json, "$.['foo.bar'].key")); 

However in bigquery this type of espcaping attempts cause Error: JSONPath parse error errors.

2 Answers

use backtick to escape (it is also used to escape hyphen in project/dataset name)

SELECT JSON_VALUE(json_field.`key.value`) AS feature FROM tablename    
Related