* * *

Author Topic: new JSON parser  (Read 3399 times)

DonaldShimoda

  • Jr. Member
  • **
  • Posts: 58
    • Parallel Pascal Worlds
Re: new JSON parser
« Reply #15 on: December 07, 2016, 03:35:20 pm »
The superobject json parser or successor to it is in the mOrMot library I believe See http://synopse.info. But that is json bloatware ;) (but really well written if you can use all that overhead that belongs in separate units)

I can't find a simple example on mormot to get a Json string and access the field, like this

create JSON (on xsuperobject)

Code: Pascal  [Select]
  1.     soRegistrarVenta                       := XSuperObject.TSuperObject.Create;
  2.     soRegistrarVenta.S['Llave']         := fLlave;

or this

parse JSON (using superobject)

Code: Pascal  [Select]
  1.       soRespuesta :=  SuperObject.so(result);
  2.       aString        := soRespuesta['Periodo'].AsString;

Better have a look at the standard fcl-json package first. It comes with FPC.

I need a library working in both, delphi and lazarus.
« Last Edit: December 07, 2016, 03:39:29 pm by DonaldShimoda »

Thaddy

  • Hero Member
  • *****
  • Posts: 3195
Re: new JSON parser
« Reply #16 on: December 07, 2016, 07:02:59 pm »
AFAIK mOrMot works in both Delphi and Freepascal/Lazarus.
As I wrote you may be better of with fcl-json. It comes with examples. Particulary the parsedemo.pp does what you want in a simple way.

Remy Lebeau

  • Full Member
  • ***
  • Posts: 210
    • Lebeau Software
Re: new JSON parser
« Reply #17 on: December 07, 2016, 08:40:16 pm »
everything json tends to be waywaaaaaaaaaaaaaaaaay over complicated and codebloated for such a simple syntax.

That "simple syntax" also causes a number of issues, as the JSON spec has holes in it that are open to interpretation in parsers.  I recently read a fairly detailed whitepaper (which I can't find now, I wish I had saved it) analyzing the issues in the spec and how various parsers try to deal with them in different ways.  So JSON, while simple in nature, is not without its share of problems, especially in the area of exchanging data between systems.  There are compatibility issues to watch out for.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) open source project - Admin, Developer

DonaldShimoda

  • Jr. Member
  • **
  • Posts: 58
    • Parallel Pascal Worlds
Re: new JSON parser
« Reply #18 on: December 07, 2016, 09:03:24 pm »
everything json tends to be waywaaaaaaaaaaaaaaaaay over complicated and codebloated for such a simple syntax.

That "simple syntax" also causes a number of issues, as the JSON spec has holes in it that are open to interpretation in parsers.  I recently read a fairly detailed whitepaper (which I can't find now, I wish I had saved it) analyzing the issues in the spec and how various parsers try to deal with them in different ways.  So JSON, while simple in nature, is not without its share of problems, especially in the area of exchanging data between systems.  There are compatibility issues to watch out for.

Hi Remmy, glad to see you here. Any recommendation? I can't find a mormot sample to manage the code posted.

Best regards.

avra

  • Hero Member
  • *****
  • Posts: 865
    • Additional info
Re: new JSON parser
« Reply #19 on: April 17, 2017, 01:24:43 pm »
Hi All!
just published a pascal port of the jsmn code.
this is an small and extremly fast json parser
https://github.com/blestan/jsmn

This link is dead now. Can anyone please attach a saved archive of it?

I need this for a small system with no OOP, so any other JSON lib is too big for available resources. Initially I wanted to convert JSMN myself but remembered that someone has already done it and refound this topic. Unfortunately Blestan's conversion is no longer available.
ct2laz - Easily convert components and projects between Lazarus and CodeTyphon

Blestan

  • Sr. Member
  • ****
  • Posts: 261
Re: new JSON parser
« Reply #20 on: April 17, 2017, 01:44:23 pm »
hi! im the creator of the parser ... the json parser evolved in fpc-xon ...
json is one of the format that xon can handle
but the passer is still lightweigt and based of jsmn

check fpc-xon
https://github.com/blestan/fpc-xon

its pretty stable and usable as json parser (
im using it in may own rest api server )  and far more simple to use because it's not oop ...

« Last Edit: April 17, 2017, 01:50:31 pm by Blestan »

avra

  • Hero Member
  • *****
  • Posts: 865
    • Additional info
Re: new JSON parser
« Reply #21 on: April 17, 2017, 02:23:11 pm »
the json parser evolved in fpc-xon ...
json is one of the format that xon can handle
Thank you Blestan for your work. I have already looked at fpc-xon but that would be too big for resources I have available (8-bit microcontroller with just few Kb RAM). I need it to be as small as possible, and jsmn seams to be the only fit.
So, if you or anyone else still have the original jsmn conversion sources, please attach it.
ct2laz - Easily convert components and projects between Lazarus and CodeTyphon

BBasile

  • Sr. Member
  • ****
  • Posts: 264
Re: new JSON parser
« Reply #22 on: April 17, 2017, 03:17:58 pm »
Blestan, why do you call Cardinal ZigZag ?!

BBasile

  • Sr. Member
  • ****
  • Posts: 264
Re: new JSON parser
« Reply #23 on: April 17, 2017, 03:21:51 pm »
Xfloat should be of type double. There can be problem if your lib is used to GET deserialize, process, serialize POST. precision loss.

Blestan

  • Sr. Member
  • ****
  • Posts: 261
Re: new JSON parser
« Reply #24 on: April 17, 2017, 03:26:45 pm »
1/ no promlem xfloat can be changed to double asap
2/ zigzag i about converting signed integer to unisigned for easy variable length integer serialization .. this is only used in the binary serializer ( btw ... this is early stage and not too much tested in production

any ideas / bugs /comments are welcome

blestan

Blestan

  • Sr. Member
  • ****
  • Posts: 261
Re: new JSON parser
« Reply #25 on: April 17, 2017, 03:29:11 pm »
@avra the json parser in xon is praticly a jsmn port .. if you do not want to use xon you can very very easy  downgrade it to use arrays or records

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus