2.x
Ask or search…
K

Decode JSON

Decode JSON from a field and add to a key
The Decode JSON action decodes JSON data embedded in a source key, and returns it to a destination key. When added to your processing rule, the Decode JSON action parses JSON serialized data from the source keys of your data to a JSON string. This method can be useful for parsing embedded JSON data into more malleable JSON strings.
For example, given the following sample website log data with JSON under the log key:
{"log": "{\"timestamp\":\"2023-03-28T09:08:41.64283645Z\",\"user_id\":3,\"page_id\":30,\"action\":\"purchase\"}\n"}
{"log": "{\"timestamp\":\"2023-03-28T09:08:42.643343109Z\",\"user_id\":4,\"page_id\":10,\"action\":\"purchase\"}\n"}
{"log": "{\"timestamp\":\"2023-03-28T09:08:48.643600498Z\",\"user_id\":1,\"page_id\":50,\"action\":\"click\"}\n"}
{"log": "{\"timestamp\":\"2023-03-28T09:08:50.643773688Z\",\"user_id\":5,\"page_id\":40,\"action\":\"purchase\"}\n"}
{"log": "{\"timestamp\":\"2023-03-28T09:08:51.643932272Z\",\"user_id\":1,\"page_id\":30,\"action\":\"purchase\"}\n"}
{"log": "{\"timestamp\":\"2023-03-28T09:08:56.644080944Z\",\"user_id\":2,\"page_id\":40,\"action\":\"click\"}\n"}
{"log": "{\"timestamp\":\"2023-03-28T09:09:03.64425954Z\",\"user_id\":3,\"page_id\":30,\"action\":\"click\"}\n"}
{"log": "{\"timestamp\":\"2023-03-28T09:09:03.644317046Z\",\"user_id\":1,\"page_id\":20,\"action\":\"view\"}\n"}
{"log": "{\"timestamp\":\"2023-03-28T09:09:10.64447719Z\",\"user_id\":2,\"page_id\":50,\"action\":\"purchase\"}\n"}
{"log": "{\"timestamp\":\"2023-03-28T09:09:17.644810963Z\",\"user_id\":2,\"page_id\":10,\"action\":\"view\"}\n"}
{"log": "{\"timestamp\":\"2023-03-28T09:09:20.644994805Z\",\"user_id\":1,\"page_id\":50,\"action\":\"view\"}\n"}
To parse the embedded JSON data in the log key of each record:
  1. 1.
    In the processing rules tab, in the Actions dropdown, select Decode JSON.
  2. 2.
    In the Source key field, enter log.
  3. 3.
    In the Destination key field, enter decoded_json.
  4. 4.
    Click Apply.
Decode JSON Processing Rule Action
Your processing rule will now parse the JSON data from every log key in your pipeline into a JSON string. It will also add the decoded_json key as the result of the converted record.