How to split a JSON array inside an object

joerno

I have a JSON-Message with an array in an array. I want to split that into multiple events:

{
"type": "monitor",
"server": "10.111.222.333",
"host": "abc.de",
"bean": [{
    "name": "beanName1",
    "reseted": "2015-06-05T15:10:00.192Z",
    "method": [{
      "name": "getAllXY",
      "count": 5,
      "min": 3,
      "max": 5
    },
    {
      "name": "getName",
      "count": 4,
      "min": 2,
      "max": 4
    }]
  },
  {
    "name": "beanName2",
    "reseted": "2015-06-05T15:10:00.231Z",
    "method": [{
      "name": "getProperty",
      "count": 4,
      "min": 3,
      "max": 3
    }]
  },
  {
    "name": "beanName3",
    "reseted": "2015-06-05T15:10:00.231Z"
  }]
}

Using a filter to split "bean":

input {
  stdin {
    codec => "json"
  }
}

filter {
  split {
    field => "bean"
  }
}

output {
  stdout{codec => "json"}
}

is working well:

{"type":"monitor",
 "server":"10.111.222.333",
 "host":"abc.de",
 "bean":{
   "name":"beanName1",
   "reseted":"2015-06-05T15:10:00.192Z",
   "method":[{
     "name":"getAllXY",
     "count":5,
     "min":3,
     "max":5 
    },{
     "name":"getName",
     "count":4,
     "min":2,
     "max":4
    }]},
 "@version":"1",
 "@timestamp":"2015-07-14T09:21:18.326Z"
}

{"type":"monitor",
 "server":"10.111.222.333",
 "host":"abc.de",
 "bean":{
   "name":"beanName2",
   "reseted":"2015-06-05T15:10:00.231Z",
   "method":[{
     "name":"getProperty",
     "count":4,
     "min":3,
     "max":3
   }]},
 "@version":"1",
 "@timestamp":"2015-07-14T09:21:18.326Z"
}

    ...

To seperate also the "methods", I added another split-filter:

  split {
    field => "bean"
  }
  split {
    field => "bean.method"
  }

But that way I get only an error message:

Exception in filterworker {"exception"=>#LogStash::ConfigurationError: Only String and Array types are splittable. field:bean.method is of type = NilClass

I can't access the array "method" inside the object "bean". I tried different notations with no luck. Is it possible to access the array, maybe it isn't supported yet?

hurb

The following code should do what you want and return one event for each method:

filter {
    if !("splitted_beans" in [tags]) {
        json {
            source => "message"
        }
        split { 
            field => "bean"
            add_tag => ["splitted_beans"]
        }
    }

    if ( "splitted_beans" in [tags] and [bean][method] ) {
        split {
            field => "bean[method]"
        }
    }
}

The second condition checks if the first method was successful and if a method exists inside your bean. So it works for beans without methods as well.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Parsing JSON Object inside Array in Jackson

分類Dev

How do I parse a JSON which contains an array inside a json Object without a arrayName

分類Dev

how to insert an item to an array that is inside an object in mongoose?

分類Dev

How to bring out an Object that inside double array

分類Dev

React - How to pass an object inside a map array

分類Dev

Array inside array to Object

分類Dev

how to get local characters inside json array

分類Dev

How to create Array inside array for return json_encode($data)

分類Dev

How split a string into an array which i want to push inside an other array

分類Dev

How to split an array of JSON documents into fixed size chunks?

分類Dev

split an array with object to 2 arrays

分類Dev

How to iterate through an array inside object in "ng-options" attribute?

分類Dev

vue filtersearch an array of object inside an array of object

分類Dev

How to pass a react prop if it's deeply nested inside a JSON object?

分類Dev

MongoDB. How to update json property inside an array

分類Dev

How do I parse an array inside parsed JSON in Swift?

分類Dev

How to find JSON array present in JSON object or not android

分類Dev

How to push Json Array Dynamically within Json object

分類Dev

Map array inside object inside array into a single array

分類Dev

How To find If this Array has duplicate object which Has another array inside it

分類Dev

Deserialization of JSON Object as array

分類Dev

get value of object inside array inside object with javascript

分類Dev

How to access the array inside the array

分類Dev

How to split a cell inside in table by ratio

分類Dev

How to convert the following JSON array into IDictionary<string, object>?

分類Dev

how to get a particular object value from nested json array

分類Dev

How to update a complex json object based on array of objects

分類Dev

How to save array of json object in postgres using typeorm

分類Dev

how to parse only first array in the json object in android?

Related 関連記事

  1. 1

    Parsing JSON Object inside Array in Jackson

  2. 2

    How do I parse a JSON which contains an array inside a json Object without a arrayName

  3. 3

    how to insert an item to an array that is inside an object in mongoose?

  4. 4

    How to bring out an Object that inside double array

  5. 5

    React - How to pass an object inside a map array

  6. 6

    Array inside array to Object

  7. 7

    how to get local characters inside json array

  8. 8

    How to create Array inside array for return json_encode($data)

  9. 9

    How split a string into an array which i want to push inside an other array

  10. 10

    How to split an array of JSON documents into fixed size chunks?

  11. 11

    split an array with object to 2 arrays

  12. 12

    How to iterate through an array inside object in "ng-options" attribute?

  13. 13

    vue filtersearch an array of object inside an array of object

  14. 14

    How to pass a react prop if it's deeply nested inside a JSON object?

  15. 15

    MongoDB. How to update json property inside an array

  16. 16

    How do I parse an array inside parsed JSON in Swift?

  17. 17

    How to find JSON array present in JSON object or not android

  18. 18

    How to push Json Array Dynamically within Json object

  19. 19

    Map array inside object inside array into a single array

  20. 20

    How To find If this Array has duplicate object which Has another array inside it

  21. 21

    Deserialization of JSON Object as array

  22. 22

    get value of object inside array inside object with javascript

  23. 23

    How to access the array inside the array

  24. 24

    How to split a cell inside in table by ratio

  25. 25

    How to convert the following JSON array into IDictionary<string, object>?

  26. 26

    how to get a particular object value from nested json array

  27. 27

    How to update a complex json object based on array of objects

  28. 28

    How to save array of json object in postgres using typeorm

  29. 29

    how to parse only first array in the json object in android?

ホットタグ

アーカイブ