Extract selected properties from a nested JSON with logstash?

   {
      "billToLocation": {
        "prop1": "iwant",
        "prop2": {
          "prop2prop1": "iwant",
          "prop2prop2": {
            
          },
          "prop2prop3:"iDontWant
        },
        
      },
      "propIdontWant": {
        
      }
    }

The above is a sample JSON I have created to explain what I am looking for.

Let's say I want

billToLoation.prop1,

billToLoation.prop2.prop2prop1,

billToLoation.prop2.prop2prop2

and exclude everything else from the output. How do I do that?

I am very new to logstash. Based on the official documentation I tried a few combinations and permutations but nothing seems to be working.

filters-json-target

    input {
         stdin {
              codec=>json
          } 
          http {
               host=>"127.0.0.1"
               port => 8080
          }
         } 
    
    filter {
          json { source =>"billToLocation"
          target =>"newpropForResult"
            remove_field => ["propIDontWant" ]
    
          }
        }
    output {
         stdout { }
         file{
         path=> "output.txt"
         }
     }

Also, can I write my own javascript function to manipulate JSON in logstash?

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