Forum > Packages and Libraries
FPC\Lazarus Library for JSON
Gizmo:
Hi
I have manually coded some functions for reading and parsing some JSON (http://www.json.org/) structures. But I've 'done it the hard way', so to speak using various Pos values and reading string values inbetween. I wondered if there is a maintained library of sorts that would no doubt do it better?
I found http://code.google.com/p/json-fpk/ and http://code.google.com/p/delphijson/ and also mention of TJSONObject but I am struggling to find the FPC documentation for TJSONObject and I didn't want to go ahead with the first two if there's a built maintained way of doing it with Lazarus\FPC without relying on third party modules?
I also found this Delphi library : http://stackoverflow.com/questions/4350886/delphi-parse-json-string - not sure if there is the same for freepascal?
Can anyone give me some pointers for looking for and then reading JSON structures using Lazarus and FPC?
Thanks
BigChimp:
See fpctwit [1] for an example of using the built in FPC JSON units.
Note:
- Support for UTF8 encoding was only added recently (I think to FPC trunk, probably not to 2.6.1 definitely not to 2.6.0)
- fpctwit provides a UTF8 version that can be used for older fpcs; once again see the code to see how FPC version detection is done for that.
- see e.g. ProcessTweets in twitter.pas in that repository for examples on decoding json. the plurk example client code has a lot of json, too
[1] https://bitbucket.org/reiniero/fpctwit/src
Leledumbo:
--- Quote ---but I am struggling to find the FPC documentation for TJSONObject
--- End quote ---
When a package has no documentation, it's the source code and that serves it (well you have them all open, feel free to look at it, there are some examples which you can learn from).
loopbreaker:
very recently I saw this
http://delphitools.info/2012/09/17/spotlight-on-dwsjson/
Gizmo:
Thanks for the pointers guys.
I've spent the evening looking at these, and the various libraries of fpjson, jsonparser, jsonscanner and examples such as
http://fossies.org/unix/misc/fpcbuild-2.6.0.tar.gz:a/fpcbuild-2.6.0/fpcsrc/packages/fcl-json/examples/parsedemo.pp and
https://bitbucket.org/reiniero/fpctwit/src/1c14d1542918/twitter.pas and
http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/tools/jsonviewer/?root=lazarus&sortby=date and
http://fossies.org/unix/misc/fpcbuild-2.6.0.tar.gz:a/fpcbuild-2.6.0/fpcsrc/packages/fcl-json/src/README.txt
and I'm totally confused!
Having read the entry at http://delphitools.info/2012/09/17/spotlight-on-dwsjson/ , that looks to be the most easy to follow, but I wanted to avoid using "non-lazarus\non-FPC" libraries if I could, just to keep things simple.
Having read all of these simingly quite advanced examples though, I'm still unsure how I would go about even starting what I need to do. My program reads a file in buffers that is then assigned to a string variable. I then need to look at each variable to see if there is JSON data in it. If there is, I need to say "Parse this string variable for the JSON data and access the elements that you find".
Navigation
[0] Message Index
[#] Next page