05/07/2019 - PHP
You can use example below to split values into named array keys by using preg_match
function.
You need to flatten this.
{
"time_local": "2019-06-21T23:30:14+0000",
"client_ip": "-",
"remote_addr": "192.168.240.3",
"remote_user": "",
"request": "GET / HTTP/1.1",
"status": "200",
"body_bytes_sent": "0",
"request_time": "0.001",
"http_referrer": "",
"http_user_agent": "curl/7.38.0",
"request_id": "8bf75860a56458f1e37a13d1178d8938"
}
/^{"time_local":"(?<time_local>.*?)","client_ip":"(?<client_ip>.*?)","remote_addr":"(?<remote_addr>.*?)","remote_user":"(?<remote_user>.*?)","request":"(?<request>.*?)","status":"(?<status>.*?)","body_bytes_sent":"(?<body_bytes_sent>.*?)","request_time":"(?<request_time>.*?)","http_referrer":"(?<http_referrer>.*?)","http_user_agent":"(?<http_user_agent>.*?)","request_id":"(?<request_id>.*?)"}$/
preg_match($pattern, $input, $matches);
Content of $matches
variable. Full example is here.
Array
(
[0] => {"time_local":"2019-06-21T23:30:14+0000","client_ip":"-","remote_addr":"192.168.240.3","remote_user":"","request":"GET / HTTP/1.1","status":"200","body_bytes_sent":"0","request_time":"0.001","http_referrer":"","http_user_agent":"curl/7.38.0","request_id":"8bf75860a56458f1e37a13d1178d8938"}
[time_local] => 2019-06-21T23:30:14+0000
[1] => 2019-06-21T23:30:14+0000
[client_ip] => -
[2] => -
[remote_addr] => 192.168.240.3
[3] => 192.168.240.3
[remote_user] =>
[4] =>
[request] => GET / HTTP/1.1
[5] => GET / HTTP/1.1
[status] => 200
[6] => 200
[body_bytes_sent] => 0
[7] => 0
[request_time] => 0.001
[8] => 0.001
[http_referrer] =>
[9] =>
[http_user_agent] => curl/7.38.0
[10] => curl/7.38.0
[request_id] => 8bf75860a56458f1e37a13d1178d8938
[11] => 8bf75860a56458f1e37a13d1178d8938
)