0

How can I get only nested json in Logstash?

{
    "metadata_1":"Meta 1",
    "metadata_2":"Meta 2",
    ...
    "metadata_N":"Meta N",
    "mydata":{
        "name":"User Name 1",
        "surname":"User SurName 1"
    }
}

I want to get only "mydata". All "metadata" must be completely removed from the result. Logstash config:

input {
    stdin { }
}
filter {
    json {
       source => "message"
    }
}
output {
    stdout { codec => rubydebug }
}

Not worked for me:

source => "message"
source => "mydata"
source => "[message][mydata]"

The expected result is ("mydata" as root):

{
    "name":"User Name 1",
    "surname":"User SurName 1"
}

1 Answer 1

1

The prune filter should do what you want:

 prune {
   whitelist_names => ["mydata"]
 }
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. That is mostly close to what I'm looking for. But I see that result is not in root, but as "mydata" object. And "prune" does not have "target" field. And chain json filter just after "prune" like: json { source => "mydata" } has no effect.
Cool! Thanks . .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.