Lua Script working on commenting chroot /var/lib/haproxy but not when I uncomment it

Hi folks,
I’m running Lua script in integration with haproxy and it’s working fine when I comment chroot /var/lib/haproxy but it throws error when I uncomment the path in haproxy.cfg.

Can anyone please help how we can run the lua script while using the chroot /var/lib/haproxy path in haproxy.cfg ?

—haproxy.cfg—
global
lua-load /etc/haproxy/socket.lua
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon

defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000

frontend myfrontend
bind *:80
mode http
use_backend %[lua.validation_fetch]
default_backend failure

backend web1
mode http
option http-buffer-request
balance roundrobin
option forwardfor
server app_1 localhost:81 check

backend failure
errorfile 503 /etc/haproxy/errors/error.http

–Lua script–
local ltn12 = require ‘ltn12’
local http_socket = require “socket.http”
local json = require’json’

core.register_fetches(“validation_fetch”,function(txn)
local hostname = txn.sf:req_fhdr(“host”):lower()
local res = {}
r, c, h, s = http_socket.request
{
method = “GET”, – Validation API Method
url = “http://localhost:4567/auth?url=”…hostname, – Validation API URL
headers = header,
sink = ltn12.sink.table(res)
}

res = table.concat(res) --The table.concat is needed since the response could be comprised of multiple chunk sizes(appended to res as it’s received)
print(res)
print(hostname)
local value = json.decode(res).boolean
if value == true then
backend = “web1”
else
backend = “failure”
end
print (value)
print (backend)
core.Debug("Returning: " … backend)
return backend
end)

Error:
(21680) : Lua sample-fetch ‘validation_fetch’: [state-id 0] runtime error: /etc/haproxy/socket.lua:19: value expected at position 1 from [C]: in field ‘decode’, /etc/haproxy/socket.lua:19: in function line 5.

Thanks in advance!