Bulk Processing of JSON

Wednesday, 9 April 2014 · 3 messages
SF
Shaun Flynn9 Apr 2014 12:19 #

Hello there,

I am working in a project to work with train schedules.

Sadly, the data is given to me as a series of JSON objects which need to be read in line by line.

Is there a way of batch processing JSON, or do I have to submit line by line?

Shaun

CG
Christian Grün9 Apr 2014 13:13 #

Hi Shaun,

Quoted text · Shaun Flynn · 2 lines
> Sadly, the data is given to me as a series of JSON objects which need to be > read in line by line.

No problem, try this:

  for $line in file:read-text-lines('input.json')
  return json:parse($line)

If you want to store all objects in a database, you can combine the query with db:add:

  for $line at $pos in file:read-text-lines('json.json')
  return db:add('db', json:parse($line), $pos || '.xml')

Our Wiki will give you some more hints [1,2,3].

Hope this helps, Christian

[1] http://docs.basex.org/wiki/File_Module [2] http://docs.basex.org/wiki/JSON_Module [3] http://docs.basex.org/wiki/Database_Module

SF
Shaun Flynnin reply to Shaun Flynn, 9 Apr 2014, 12:199 Apr 2014 13:23 #

Spot on! Thank you very much xx

Quoted text · Shaun Flynn · 13 lines
On 9 Apr 2014 11:19, "Shaun Flynn" <scfy12 at googlemail.com> wrote: > Hello there, > > I am working in a project to work with train schedules. > > Sadly, the data is given to me as a series of JSON objects which need to > be read in line by line. > > Is there a way of batch processing JSON, or do I have to submit line by > line? > > Shaun >

⚡Generated with XQuery