new JSON parser lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Blestan · 2016-02-27 08:39 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 ---------------------------------------------------------------------- Thaddy · 2016-02-27 10:24 On first look? If that works it is like it should be done! I have been using my own json parser for a longloooooong time because everything json tends to be waywaaaaaaaaaaaaaaaaay over complicated and codebloated for such a simple syntax. I will definitely try to shoot holes in it. Tnx. I'll be back with some test results on complex (strict) json. For the other json parsers: if this works: thanks but no thanks. It hurts my  eyes and the intention of json. ---------------------------------------------------------------------- JD · 2016-02-27 12:16 Quote from: Thaddy on February 27, 2016, 11:24:41 amOn first look? If that works it is like it should be done! I have been using my own json parser for a longloooooong time because everything json tends to be waywaaaaaaaaaaaaaaaaay over complicated and codebloated for such a simple syntax. I will definitely try to shoot holes in it. Tnx. I'll be back with some test results on complex (strict) json. For the other json parsers: if this works: thanks but no thanks. It hurts my  eyes and the intention of json. What do you think of fpjsonparser & how does it compare to your own parser? JD ---------------------------------------------------------------------- Thaddy · 2016-02-27 12:37 Quote from: JD on February 27, 2016, 01:16:53 pmQuote from: Thaddy on February 27, 2016, 11:24:41 amOn first look? If that works it is like it should be done! I have been using my own json parser for a longloooooong time because everything json tends to be waywaaaaaaaaaaaaaaaaay over complicated and codebloated for such a simple syntax. I will definitely try to shoot holes in it. Tnx. I'll be back with some test results on complex (strict) json. For the other json parsers: if this works: thanks but no thanks. It hurts my  eyes and the intention of json. What do you think of fpjsonparser & how does it compare to your own parser? JD Actually pretty well. The scanner and parser are lightweight, though not as lightweight as proposed here. Also: complexity for things that can be build on top of json are in separate units and not in the same unit or even in the same set of classes (mOrmot json overbloat). Structurally it is very sound. ---------------------------------------------------------------------- JD · 2016-02-27 12:46 Quote from: Thaddy on February 27, 2016, 01:37:34 pmActually pretty well. The scanner and parser are lightweight, though not as lightweight as proposed here. Also: complexity for things that can be build on top of json are in separate units and not in the same unit or even in the same set of classes (mOrmot json overbloat). Structurally it is very sound. I tried mORMot's json units too. I spent too much time trying to understand it so I gave up. JD ---------------------------------------------------------------------- Blestan · 2016-02-27 12:51 this one is very very fast... for now i tested it with prety large jsons from the web and it works super correct .. but who knows ... \ now i'm triing to make it more pascalish ) the original i c .. any suggestions are wellcome ---------------------------------------------------------------------- argb32 · 2016-02-27 12:56 Does it work with unicode? ---------------------------------------------------------------------- Blestan · 2016-02-27 13:03 json specification defines input string as utf8. for now i not planing to implement string escape during parsing (only backslash i monitored to avoid problems with \"  .... may be this can  this be done later in the program or controled by flag in the parser ---------------------------------------------------------------------- Thaddy · 2016-02-27 13:56 as per json.org the backslash is for escaping. ---------------------------------------------------------------------- Blestan · 2016-02-27 13:59 exaclty i'm cheking for backslaches but do not unescape chars ---------------------------------------------------------------------- JD · 2016-02-27 14:01 Quote from: Blestan on February 27, 2016, 01:51:47 pmthis one is very very fast... for now i tested it with prety large jsons from the web and it works super correct .. but who knows ... \ now i'm triing to make it more pascalish ) the original i c .. any suggestions are wellcome I'll be keeping an eye on the results of the tests of your json parser. Thanks for sharing JD ---------------------------------------------------------------------- Thaddy · 2016-02-27 15:10 Quote from: Blestan on February 27, 2016, 02:59:28 pmexaclty i'm cheking for backslaches but do not unescape chars Maybe introducing a simple stack at the point where you encounter the slash would be sufficient. Pattern is process, enter next char on stack, process as literal, pop. Seems very little is needed from what I read. Need help? ---------------------------------------------------------------------- Blestan · 2016-02-28 01:00 for escaping a string we do not need a stack  the main problem is string realloc. and ofcourse resolving all tokens even if they are not used .... so all resolving will be done only when needed ---------------------------------------------------------------------- DonaldShimoda · 2016-12-07 13:25 Quote from: Blestan on February 27, 2016, 09:39:44 amHi All! just published a pascal port of the jsmn code. this is an small and extremly fast json parser https://github.com/blestan/jsmn The library is not there anymore. I want to test this. I need a library compatible with delphi and fps ala superobjetc or xsuperobjetc. Can you please tell me what happen to your code? Thanks ---------------------------------------------------------------------- Thaddy · 2016-12-07 13:49 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) Better have a look at the standard fcl-json package first. It comes with FPC. ---------------------------------------------------------------------- DonaldShimoda · 2016-12-07 14:35 Quote from: Thaddy on December 07, 2016, 02:49:01 pmThe 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     soRegistrarVenta                       := XSuperObject.TSuperObject.Create;    soRegistrarVenta.S['Llave']       := fLlave; or this parse JSON (using superobject) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       soRespuesta :=  SuperObject.so(result);      aString        := soRespuesta['Periodo'].AsString; Quote from: Thaddy on December 07, 2016, 02:49:01 pmBetter have a look at the standard fcl-json package first. It comes with FPC. I need a library working in both, delphi and lazarus. ---------------------------------------------------------------------- Thaddy · 2016-12-07 18:02 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 · 2016-12-07 19:40 Quote from: Thaddy on February 27, 2016, 11:24:41 ameverything 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. ---------------------------------------------------------------------- DonaldShimoda · 2016-12-07 20:03 Quote from: Remy Lebeau on December 07, 2016, 08:40:16 pmQuote from: Thaddy on February 27, 2016, 11:24:41 ameverything 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 · 2017-04-17 11:24 Quote from: Blestan on February 27, 2016, 09:39:44 amHi 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. ---------------------------------------------------------------------- Blestan · 2017-04-17 11:44 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 ... ---------------------------------------------------------------------- avra · 2017-04-17 12:23 Quote from: Blestan on April 17, 2017, 01:44:23 pmthe json parser evolved in fpc-xon ... json is one of the format that xon can handleThank 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. ---------------------------------------------------------------------- guest58172 · 2017-04-17 13:17 Blestan, why do you call Cardinal ZigZag ?! ---------------------------------------------------------------------- guest58172 · 2017-04-17 13:21 Xfloat should be of type double. There can be problem if your lib is used to GET deserialize, process, serialize POST. precision loss. ---------------------------------------------------------------------- Blestan · 2017-04-17 13:26 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 · 2017-04-17 13:29 @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