* * *

Author Topic: new JSON parser  (Read 5470 times)

Blestan

  • Sr. Member
  • ****
  • Posts: 452
new JSON parser
« on: February 27, 2016, 09:39:44 am »
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
Speak postscript or die!
Translate to pdf and live!

Thaddy

  • Hero Member
  • *****
  • Posts: 4516
Re: new JSON parser
« Reply #1 on: February 27, 2016, 11:24:41 am »
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.
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

JD

  • Hero Member
  • *****
  • Posts: 1596
Re: new JSON parser
« Reply #2 on: February 27, 2016, 01:16:53 pm »
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.

What do you think of fpjsonparser & how does it compare to your own parser?

JD
Windows (10, 7) - Lazarus 1.8RC4/FPC 3.0.4 (also Delphi occasionally)
Linux Mint Cinnamon  - Lazarus 1.6.4/FPC 3.0.2
Indy 10.6 series; Zeos 7.2.1; SQLite, Firebird, PostgreSQL & MariaDB

Thaddy

  • Hero Member
  • *****
  • Posts: 4516
Re: new JSON parser
« Reply #3 on: February 27, 2016, 01:37:34 pm »
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.

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.
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

JD

  • Hero Member
  • *****
  • Posts: 1596
Re: new JSON parser
« Reply #4 on: February 27, 2016, 01:46:25 pm »
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.

I tried mORMot's json units too. I spent too much time trying to understand it so I gave up.

JD
Windows (10, 7) - Lazarus 1.8RC4/FPC 3.0.4 (also Delphi occasionally)
Linux Mint Cinnamon  - Lazarus 1.6.4/FPC 3.0.2
Indy 10.6 series; Zeos 7.2.1; SQLite, Firebird, PostgreSQL & MariaDB

Blestan

  • Sr. Member
  • ****
  • Posts: 452
Re: new JSON parser
« Reply #5 on: February 27, 2016, 01:51:47 pm »
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

Speak postscript or die!
Translate to pdf and live!

argb32

  • Jr. Member
  • **
  • Posts: 71
    • Pascal IDE based on IntelliJ platform
Re: new JSON parser
« Reply #6 on: February 27, 2016, 01:56:31 pm »
Does it work with unicode?

Blestan

  • Sr. Member
  • ****
  • Posts: 452
Re: new JSON parser
« Reply #7 on: February 27, 2016, 02:03:57 pm »
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
Speak postscript or die!
Translate to pdf and live!

Thaddy

  • Hero Member
  • *****
  • Posts: 4516
Re: new JSON parser
« Reply #8 on: February 27, 2016, 02:56:22 pm »
as per json.org the backslash is for escaping.
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

Blestan

  • Sr. Member
  • ****
  • Posts: 452
Re: new JSON parser
« Reply #9 on: February 27, 2016, 02:59:28 pm »
exaclty i'm cheking for backslaches but do not unescape chars
Speak postscript or die!
Translate to pdf and live!

JD

  • Hero Member
  • *****
  • Posts: 1596
Re: new JSON parser
« Reply #10 on: February 27, 2016, 03:01:57 pm »
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

I'll be keeping an eye on the results of the tests of your json parser.

Thanks for sharing

JD
Windows (10, 7) - Lazarus 1.8RC4/FPC 3.0.4 (also Delphi occasionally)
Linux Mint Cinnamon  - Lazarus 1.6.4/FPC 3.0.2
Indy 10.6 series; Zeos 7.2.1; SQLite, Firebird, PostgreSQL & MariaDB

Thaddy

  • Hero Member
  • *****
  • Posts: 4516
Re: new JSON parser
« Reply #11 on: February 27, 2016, 04:10:36 pm »
exaclty 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?
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

Blestan

  • Sr. Member
  • ****
  • Posts: 452
Re: new JSON parser
« Reply #12 on: February 28, 2016, 02:00:25 am »
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
Speak postscript or die!
Translate to pdf and live!

DonaldShimoda

  • Jr. Member
  • **
  • Posts: 71
    • Parallel Pascal Worlds
Re: new JSON parser
« Reply #13 on: December 07, 2016, 02:25:56 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

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

  • Hero Member
  • *****
  • Posts: 4516
Re: new JSON parser
« Reply #14 on: December 07, 2016, 02:49:01 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)

Better have a look at the standard fcl-json package first. It comes with FPC.
« Last Edit: December 07, 2016, 02:52:49 pm by Thaddy »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

 

Recent

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