You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used a single row here because the public dataset is 14GB and unpartitioned.
Desired Output: bqutils.fn.json_extract_values returns a usable value (even just a json string) of the contents of those objects.
Thanks!
The text was updated successfully, but these errors were encountered:
sgoley
changed the title
Request: Handling for objects in json_extract_keys function
Request: Handling for objects in json_extract_values function
Feb 24, 2023
Alternative might be to build something like this as a whole separate UDF:
-- extract all key value pairs as an array from a json dict
-- input: json string with a dictionary
-- returns: list of struct <key, value>
CREATE TEMP FUNCTION EXTRACT_KV_PAIRS(json_str STRING)
RETURNS ARRAY<STRUCT<key STRING, value STRING>>
LANGUAGE js AS """
try{
const json_dict = JSON.parse(json_str);
const all_kv = Object.entries(json_dict).map(
(r)=>Object.fromEntries([["key", r[0]],["value",
JSON.stringify(r[1])]]));
return all_kv;
} catch(e) { return [{"key": "error","value": e}];}
""";
@plaflamme Just contributed the json_extract_key_value_pairs function in #408 which should help with this use case, please let us know if there are any issues
Issue:
bqutils.fn.json_extract_values
returns unusable values[object Object]
when children are objects / sub collections.Example:
Sample query:
I used a single row here because the public dataset is 14GB and unpartitioned.
Desired Output:
bqutils.fn.json_extract_values
returns a usable value (even just a json string) of the contents of those objects.Thanks!
The text was updated successfully, but these errors were encountered: