I am trying to read a JSON file and trying to display some of its content. But as I try this, I get an error saying attempt to call a nil value as also shown below.
I could not understand the reason for this. Here is the latex code I am trying to run as lualatex ty.tex
\documentclass{report}
\usepackage{luacode}
\begin{document}
% load json file
\begin{luacode}
function read(file)
local handler = io.open(file, "rb")
local content = handler:read("*all")
handler:close()
return content
end
JSON = (loadfile "JSON.lua")()
table = JSON:decode(read("sample.json"))
\end{luacode}
The name of the document is \directlua{tex.print(table['documentName'])} with ID as \directlua{tex.print(table['documentId'])} and mac-protocol-id as \directlua{tex.print(table['macProtocolID'])}
The name of the company is \directlua{tex.print(table['headerFooter']['header]['left'])}
\end{document}
Here is the file named sample.json that I am trying to read from the above code:
{
"documentName": "MTRD Report",
"documentId": "D-FF/1",
"documentGeneratedAt": "06-05-2019",
"documentGeneratedBy": "admin@foo.com",
"macProtocolID": "CV/1",
"headerFooter": {
"header": {
"left": "AA, Head Office (CC, DD)",
"right": "For Restricted Circulation Only"
},
"footer": {
"left": "DFFF/1"
}
}
}
What could be the reason for the error? What mistake am I making?

['header]should be['header']. – Henri Menke May 06 '19 at 09:17