How to Parse Json http body from a POST request with tcp plugin

I send a Post request with a json content from PostMan to logstash pipeline with an input tcp plugin , the model of my data is like :

{
 "results:[
   values :"\"{..json object.. }\""

 ]
 }

my logstahs input is :

```
input{
        tcp {
            port => 433
			codec => "json"
		}
}
and the filter logstash is like : 

 ```
 filter{
     split { field => "[results]" }
     json { source => "[results][value]"}
 }

But I have the error message from logstash :

   [2020-07-09T18:11:01,432][WARN ][logstash.filters.split   ] Only String and Array types are 
    splittable. field:[results] is of type = NilClass
   [2020-07-09T18:11:01,462][ERROR][logstash.codecs.json     ] JSON parse error, original data now 
   in message field {:error=>#<LogStash::Json::ParserError: incompatible json object 
   type=java.lang.String , only hash map or arrays are supported>, 
   :data=>"\"pageRank\\\":\\\"2\\\",\\\"model\\\":\\\"PI\\\",\\\"data\\\" 
{}}],\\\"file\\\":\\\"doc.pdf\\\",\\\"hashtype\\\":\\\"sha256\\\",\\\"hash\\\":

how can i resolve that please and transform the values String to a json please ?

The tcp input processes lines as events. If your JSON object is spread across multiple lines that is not going to work.

Hi Badger So i have to transform to plain and delete all the \n ?

That should help.

1 Like

I used the http input plugin

   input {
           tcp {
                port => 433
    		}
        }
    filter{
               split { field => "[results]" }
               json { source => "[results][value]"}
           }   

and it works , i don't recommend to use tcp in this use case

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