# How to Use JSON with Logstash?

If you have JSON-formatted logs that you want to ingest and process with Logstash, follow these steps:

Assuming you have logs in the following JSON format:

```text
{"status": 200, "ip": "127.0.0.1", "level": 30, "msg": "Connected to database", "pid": 17089, "timestamp": 1696150204}
{"status": 200, "ip": "127.0.0.1", "level": 30, "msg": "Task completed successfully", "pid": 17089, "timestamp": 1696150207}
```

You can read these JSON logs with the following Logstash configuration:


```text
[label /etc/logstash/conf.d/logstash.conf]
input {
  file {
    type => "json"
    path => "/var/log/mylogs.log"
  }
}

filter {
  json {
    source => "message"
  }
}

output {
  file {
    path => "/var/log/out.log"
  }
}
```

This Logstash configuration reads JSON data from `/var/log/mylogs.log`, parses it using the JSON filter, and outputs the processed data to `/var/log/out.log`. Each incoming event (or log line) has the JSON message field parsed, and the resulting structured data is written to the output file.

