I have a Google Big Query Table column, which contains a json string. Over time, new keys were introduced to this json string.
time col_b
--------------------------------------------------
timestamp3 {"key1": "value", "key2": "value"}
timestamp2 {"key1": "value"}
timestamp1 {"key1": "value"}
How can I extract key2 and in case it doesn't exist fill with NaN? I thought about something like:
SELECT
JSON_EXTRACT(col_b, "$.key2) AS key2
FROM db;
Doing this will throw the error, so it thinks it should be a double instead of a string cause of the null values.
Bad double type: value
How can I check in advance whether key2 is existing and if not fill with null?