How to flatten the json, not working with previous post

Hi All

I have a case, wherein i need to flatten the json data.To get started i am just following the previous post.
But i am not successful with the result

I am getting below result

{
	"@timestamp" : "2020-03-08T15:09:09.688Z",
	"message" : "        \"input\": {\r",
	"@version" : "1",
	"path" : "/bin/file_data/json_data.json",
	"host" : "xxxx",
	"type" : "json"
}{
	"@timestamp" : "2020-03-08T15:09:09.698Z",
	"message" : "            \"information\": {\r",
	"@version" : "1",
	"path" : "/bin/file_data/json_data.json",
	"host" : "xxxxx",
	"type" : "json"
}{
	"@timestamp" : "2020-03-08T15:09:09.698Z",
	"message" : "            \"value\": {\r",
	"@version" : "1",
	"path" : "/bin/file_data/json_data.json",
	"host" : "xxxxx",
	"type" : "json"
}{
	"@timestamp" : "2020-03-08T15:09:09.708Z",
	"message" : "                    \"AVB\"\r",
	"@version" : "1",
	"path" : "/bin/file_data/json_data.json",
	"host" : "xxxxx",
	"type" : "json"
}
.....

This is my conf file

input{
file {
path => "/bin/file_data/json_data.json"
sincedb_path => "/bin/file_data/sincedb.txt"
type => "json"
start_position => "beginning"
}
}

filter {

ruby {
path => '/flattenJSON.rb'
script_params => { field => "body" }

}

}

output {
file {
path => "/test/test.json"
}
}

You appear to have a file containing a pretty-printed JSON object. You will need to use a multiline codec to consume it. Take a look at this.

Okay, i tried with single line json file, i got some improvement, but still no result

`Below is my result

{"body" :{"BlockName":"SA","input" : {"type" :"array","identification" :"iValue","configs" : {},"information" : {"location" :"Users\\files\\","client_id" : "abd"},"value" : {"info" :["Apple","MSFT", "AVB"],"domains" : ,"uniqueId" : "1108738857225224193","restul_set" : [0.4112226366996765, 0.34098902344703674, 0.24778836965560913],"timestamp" :1554940800000,"text" :"Test Text"}}},"result" :0.06}

My expectation is to get the data like this

body.BlockName: SA
body.input.type: array
body.input.identification: iValue

.....

`

OK, so you need a json filter.

okay i added the json file, then also same result, i am not getting the flattened json as mentioned in that post

i am using version, 6.8.4

json {
    source => "message"
    target => "message"
}

Try 'target => "body"'.

1 Like

it worked.Thanks

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