It's very easy to integrate ndjson using LuaRT ecosystem.
You can create an ndjson module like this one :
ndjson.,lua
local json = require "json"
return function (src)
local result = {}
local t = type(src)
if t == "File" then
local data = src:open()
for line in each(data.lines) do
result[#result+1] = json.decode(line)
end
elseif t == "string" then
for line in each(src:gmatch("([^\n]*)\n?")) do
result[#result+1] = json.decode(line)
end
else
error("cannot decode ndjson from '"..t.."'")
end
return result
end
And you can test this with :
test.lua
local ndjson = require "ndjson"
-- parse ndjson and return a table with all the results
local result = ndjson([[
{"name": "Alice", "age": 25}
{"name": "Bob", "age": 30}
{"name": "Charlie", "age": 22}
]])
for t in each(result) do
print(t.name, t.age)
end
As you can see you can use a string or a File object as a ndjson string.
I might add this module to the LuaRT modules for next release, thank you for the suggestion