Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stream based JSON parsing on Swift

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

like image 805
vj9 Avatar asked Aug 24 '16 12:08

vj9


People also ask

Can JSON be streamed?

JSON streaming comprises communications protocols to delimit JSON objects built upon lower-level stream-oriented protocols (such as TCP), that ensures individual JSON objects are recognized, when the server and clients use the same one (e.g. implicitly coded in).

What is JSON parsing in Swift?

Swift JSON ParsingJSON stands for JavaScript Object Notation. It's a popular text-based data format used everywhere for representing structured data. Almost every programming language supports it with Swift being no exception. You are going to use JSON a lot throughout your career, so make sure you don't miss out.

What is Jsonserialization in Swift?

An object that converts between JSON and the equivalent Foundation objects.


1 Answers

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)

like image 59
Arun Balakrishnan Avatar answered Sep 19 '22 16:09

Arun Balakrishnan