Extracting JSON key and values to separated fields

Hi, I need help with processing JSON file. My input looks like this (I need to keep it intact):

input {     
    s3 {
    bucket => "${S3_BUCKET}"
    access_key_id => "${S3_ACCESS_KEY}"
    secret_access_key => "${S3_SECRET_KEY}"
    exclude_pattern => "^.*(?<!txt|json)$"

JSON I'm trying to parse looks like this:


I've tried JSON filter, custom ruby code, but the main problem is that key is unknown. Only certain thing is structure. So, I need to extract first (only) key of this JSON to a new field, and its value (array) to another field:

url : "unknown_url"
parameters : [ "ad", "rsl", "vbf"]


filter {
    json {
        source => "message"
        target => "json"
    if "_jsonparsefailure" not in [tags]  {
        ruby {
            code => "
                json_data = event.get('[json]')
                event.set('url', json_data.keys[0])
                event.set('parameters', json_data[json_data.keys[0]])
        mutate { 
            remove_field => ["message"] 
            remove_field => ["json"] 

This can help.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.