# Parse either json or non json logs in logstash

**URL:** <https://discuss.elastic.co/t/parse-either-json-or-non-json-logs-in-logstash/375771>\
**Category:** Logstash\
**Created:** [March 12, 2025, 10:44am UTC](https://discuss.elastic.co/t/parse-either-json-or-non-json-logs-in-logstash/375771 "2025-03-12T10:44:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex\_petrov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_petrov/32/105688_2.png) [@alex\_petrov](https://discuss.elastic.co/u/alex_petrov)\
**Post date:** [March 12, 2025, 10:44am UTC](https://discuss.elastic.co/t/parse-either-json-or-non-json-logs-in-logstash/375771/1 "2025-03-12T10:44:39Z")

</div>

here is my log messages with two farmats in response section :  
this one non json in response

```auto
2025-03-12 10:52:19,645 INFO REQUEST:/auth/authorize?response_type=code RESPONSE:APPROVED amount:1000

```

this one json in reponse :

```auto
2025-03-12 10:52:19,645 INFO REQUEST:/auth/authorize?response_type=code RESPONSE:{"access_token":" ******"}

```

I used :  
`json { source => "responseBody" target => "response" }`  
but I have both non json and json in response , how can I parse both ?

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [March 12, 2025, 1:32pm UTC](https://discuss.elastic.co/t/parse-either-json-or-non-json-logs-in-logstash/375771/2 "2025-03-12T13:32:10Z")

</div>

Can you share the rest of your pipeline?

How are you creating the `responseBody` field?

You will need to validate if this field is a json or not, by checking if it has the `{` in the value for example and then use a conditional to parse it as a json and store in a different field as well as you cannot use the same field for both.

---

<div class="post-metadata">

**Author:** ![alex\_petrov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_petrov/32/105688_2.png) [@alex\_petrov](https://discuss.elastic.co/u/alex_petrov)\
**Post date:** [March 16, 2025, 8:36am UTC](https://discuss.elastic.co/t/parse-either-json-or-non-json-logs-in-logstash/375771/3 "2025-03-16T08:36:49Z")

</div>

this is an example of non json response :  
`RESPONSE:APPROVED amount:1000`  
how to use if conditional in this case , the response doesn't contain { .
