Recent

Author Topic: new JSON parser  (Read 15347 times)

Blestan

  • Sr. Member
  • ****
  • Posts: 461
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: 14157
  • Probably until I exterminate Putin.
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.
Specialize a type, not a var.

JD

  • Hero Member
  • *****
  • Posts: 1848
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 - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

Thaddy

  • Hero Member
  • *****
  • Posts: 14157
  • Probably until I exterminate Putin.
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.
Specialize a type, not a var.

JD

  • Hero Member
  • *****
  • Posts: 1848
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 - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

Blestan

  • Sr. Member
  • ****
  • Posts: 461
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: 89
    • 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: 461
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: 14157
  • Probably until I exterminate Putin.
Re: new JSON parser
« Reply #8 on: February 27, 2016, 02:56:22 pm »
as per json.org the backslash is for escaping.
Specialize a type, not a var.

Blestan

  • Sr. Member
  • ****
  • Posts: 461
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: 1848
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 - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

Thaddy

  • Hero Member
  • *****
  • Posts: 14157
  • Probably until I exterminate Putin.
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?
Specialize a type, not a var.

Blestan

  • Sr. Member
  • ****
  • Posts: 461
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

  • Full Member
  • ***
  • Posts: 109
    • 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: 14157
  • Probably until I exterminate Putin.
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 »
Specialize a type, not a var.

 

TinyPortal © 2005-2018