15

How to parse JSON being downloaded as a stream on Swift? The stream gives incomplete JSON data each time. This is because I have to download MBs of data, the main component of which is a long array of objects, and I do not want the user to wait till I get the complete data. Is it possible to keep parsing the JSON data sequentially while streaming? Basically, something like what Jackson allows on Android, or a YAJLiOS Parser implementation for Swift

vj9
  • 1,546
  • 1
  • 11
  • 18

1 Answers1

10

Basically, what you require is a SAX parser. NSJSONSerialization is a DOM parser. One such implementation for sax parsing is here

https://github.com/dhoerl/SAX-JSON-Parser-ForStreamingData

where the data is parsed as and when the data is received. For more info check this answer iPad - Parsing an extremely huge json - File (between 50 and 100 mb)

Arun Balakrishnan
  • 1,462
  • 1
  • 12
  • 24
  • Yeah, this is again an Obj-C based approach. I was looking for something Swift based actually. – vj9 Apr 23 '18 at 13:01