2

I was wondering if BigQuery has any additional support to JSON paths, as it seems like this is such a common way to work with nested data in BigQuery. For example, as a few years ago it seemed like the answer was: What JsonPath expressions are supported in BigQuery?, i.e., "Use a UDF".

However, it seems like using a path within an array, such as:

`$..Job'

Is such a common operation given BigQuery's repeated field, that about 70% of the times I've tried to use BigQuery's JSON_EXTRACT, I run into the limitation of having to iterate down an array.

Is this ability supported yet in BigQuery, or are there plans to support it, without having to do a UDF? As nice as something like the following works:

CREATE TEMPORARY FUNCTION CUSTOM_JSON_EXTRACT(json STRING, json_path STRING)
RETURNS STRING
LANGUAGE js AS """
    try { var parsed = JSON.parse(json);
        return JSON.stringify(jsonPath(parsed, json_path));
    } catch (e) { return null }
"""
OPTIONS (
    library="gs://xx-bq/jsonpath-0.8.0.js"
);
SELECT CUSTOM_JSON_EXTRACT(to_json_string(Occupation), '$..Job'), to_json_string(MovieInfo), json_extract(MovieInfo, '$.Platform') FROM `xx-163219.bqtesting.xx` LIMIT 1000

It ends up taking anywhere between 4-6x longer than a normal JSON_EXTRACT function (2s vs. about 10s). Or, is there something that I'm missing with what you're able to do with JSON objects in BQ?

David542
  • 104,438
  • 178
  • 489
  • 842
  • You can vote for this feature request [support complete JSONPath syntax](https://issuetracker.google.com/issues/128813374). So NO - it is not supported [hopefully yet]. And it is unknown [yet] if there is a plan for it – Mikhail Berlyant Jun 06 '19 at 05:28
  • @MikhailBerlyant upvoted -- at least to go down an array seems really strange/limiting here, I'm surprised this hasn't been modified. – David542 Jun 06 '19 at 18:36
  • 1
    Google / BigQuery Team quite responsive and take requests seriously. But we need to have more votes for them to prioritize it respectively. Honestly - I am also surprised that JSONPATH is not fully supported. Such a needed feature!! – Mikhail Berlyant Jun 06 '19 at 18:38

1 Answers1

0

Currently, the support for JSONPath on BigQuery includes and is limited to $, ., and [], where the latter can be either a child operator or a subscript (array) operator.

Other syntax elements from JSONPath are not supported, but for future reference, there's a public feature request to support complete JSONPath syntax.

Héctor Neri
  • 1,384
  • 9
  • 13
  • Right, that is the reason why this question was asked in the first place. Is there an update on this feature/bug ticket? – David542 Jun 20 '19 at 21:54
  • There have been some development and work in progress for JSONPath-related features. For example, one thing to notice is that Legacy SQL has more limited support than Standard SQL since Legacy won't be developed further. But, ideally people interested in this can up-vote the feature request and receive related updates on it. – Héctor Neri Jun 20 '19 at 23:18