parse_yaml(string)
Converts a YAML <string> to JSON format.
CREATE OR REPLACE FUNCTION `justfunctions.eu.parse_yaml`(`string` string) RETURNS json
LANGUAGE js AS r'''try {
return jsyaml.load(string);
} catch(e) {
return '{}';
}
''' OPTIONS ( description = '''Converts a YAML <string> to JSON format.''' , library = [ "gs://justfunctions/bigquery-functions/js-yaml.min.js" ] )
Example
SELECT `justfunctions.eu.parse_yaml`("---
updated_at:
- 2023-11-12 08:08:25.291779000 Z
- 2023-11-12 08:25:18.648572080 Z
status:
- new
- canceled
")
{'status': ['new', 'canceled'], 'updated_at': ['2023-11-12T08:08:25.291Z', '2023-11-12T08:25:18.648Z']}