Page 1 of 1

NDJSON?

Posted: Fri Feb 24, 2023 3:14 pm
by stam
Hi all,

one of our data analysts has asked for an output of data in NDJSON format - this was a new one to me. Apparently this is 'New line Delimited JSON'. The spec can be found here: https://github.com/ndjson/ndjson-spec

Data is a straight output from an SQL database and it shouldn't be an issue to export as JSON - but not sure in real terms how that would be different from NDJSON... is there a difference?

Many thanks
Stam

Re: NDJSON?

Posted: Tue Feb 28, 2023 4:37 pm
by livecode-atc
Hello everyone
From what I can understand, the NDJSON consists of one JSON for each line. So you can create a couple of functions using JSONtoArray and ArrayToJSON.

Code: Select all

-- NDJSONtoArray
function NDJSONtoArray pNDJSON
   local tIndex = 0, tArray
   
   repeat for each line tJSON in pNDJSON
      add 1 to tIndex
      put JSONtoArray(tJSON ) into tArray[tIndex]
   end repeat
   
   return tArray
end NDJSONtoArray 

-- ArrayToNDJSON
function ArrayToNDJSON pArray
   local tIndex = 0, tNDJSON
   
   repeat for each element tArray in pArray
      put ArrayToJson(tArray) & cr after tNDJSON
   end repeat
   
   return tNDJSON
end ArrayToNDJSON

Re: NDJSON?

Posted: Thu Mar 02, 2023 8:12 pm
by stam
livecode-atc wrote:
Tue Feb 28, 2023 4:37 pm
Hello everyone
From what I can understand, the NDJSON consists of one JSON for each line. So you can create a couple of functions using JSONtoArray and ArrayToJSON.
thanks @livecode-atc I'll give that a whirl and see if that satisfies our data analysts. Predictably their next best choice was 'CSV' - Big sigh...
(I still don't understand why 90% of the IT world rely on this sh***y format). I'm tempted to just email them all the link to Richard's article https://www.fourthworld.com/embassy/art ... t-die.html but have to rely on their good will for now...

thanks once again,
Stam