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
Asked
Active
Viewed 2,532 times
15
-
Wow, no action on this in over a year and a half. – Brill Pappin Apr 04 '18 at 19:58
-
2JSON parsing is not hard at all. Why not write your own parser? – drewag Apr 20 '18 at 21:37
-
2Maybe is better approach if you send the `json` from the server in parts. I mean, X number of elements each time – Benjamin RD Apr 22 '18 at 19:51
1 Answers
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