[fpc-pascal] [Lazarus] Tests results of several pascal based JSON parsers
Anthony Walter
sysrpl at gmail.com
Sat Aug 31 15:39:11 CEST 2019
> Could you include https://github.com/BeRo1985/pasjson in the comparison?
Sure. I also have a few other people have requested. I will also list the
license of each in the first table.
Regarding a huge gigabytes of JSON in a file, I know a small portion of
programmers of people might be inclined use it as an offline database
format much like CSV. Even though by far most JSON is used with
XMLHttpRequest, REST APIS, or storing settings and configurations, there
are bound to be endless requests for use cases with JSON.
For example to accommodate the reading a huge files as indoividual records
a helper class operating outside the definition of a JSON parser could
accomplish this goal. For example, it would be relatively easy to write in
a separate file:
type
TJsonStreamReader = class
public
constructor Create(Stream: TStream; OwnsStream: Boolean = False);
constructor CreateFromFile(const FileName: string);
destructor Destroy;
function Read(out Parser: TSomeJsonParser): Boolean;
end;
Then use as ...
var
R: TJsonStreamReader;
P: TSomeJsonParser;
begin
R := TJsonStreamReader.Create(InputStreamOrFileName);
try
while R.Read(P) do
// Read JSON record here
finally
R.Free;
end;
end;
And in this way a large file could be read in small blocks and given back
to the user as a parser to allow for processing of individual records. The
benefit of breaking this into its own class is that you do not need to mix
in every possible use case into the parser. You can simply write separate
use cases into their own independent units, rather than trying to make a
super class which handles every possible concern.
For example if wanted to store object state using RTTI in a JSON file,
create a separate TJsonObjectState class to handle this for you. Or if you
wanted to create a database table from a JSON file, or create a JSON file
from a database table, then again write this into its own class.
The point is, saying this JSON class does lots of these things is the wrong
approach (IMO), as these use case scenarios as likely endless and would add
unnecessary cruft to a parser. Even designing a plug in or other extensible
seems unnecessary, when simple separate classes to add functionality works
as well without all the complexity.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20190831/0769d0e2/attachment.html>
More information about the fpc-pascal
mailing list