Hive get_json_object having special characters

Hive’s get_json_object is quiet handy to query for key-value pairs if data column is a json string.

Problem comes when the key you want to look has special characters. I tumbled upon the same kind of issue very recently. Here is my json string


Extracting ‘message’ or ‘timestamp’ is straight forward with get_json_object. When you query for say ‘req.headers.connection’ it considers ‘req’ and ‘headers’ to be array and looks for ‘connection’ parameter inside it.

Here is small workaround to get its value

SELECT get_json_object(regexp_replace(`data`, 'req.headers.connection', 'connection'), '$.connection') FROM unstructured_traffic_table WHERE hour = 0 LIMIT 1;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s