NDJSON?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
stam
Posts: 2682
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

NDJSON?

Post by stam » Fri Feb 24, 2023 3:14 pm

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

livecode-atc
Posts: 2
Joined: Mon Jan 16, 2023 5:50 pm

Re: NDJSON?

Post by livecode-atc » 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.

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

stam
Posts: 2682
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: NDJSON?

Post by stam » Thu Mar 02, 2023 8:12 pm

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

Post Reply

Return to “Talking LiveCode”