Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems parsing number with JSMN_STRICT is defined #177

Open
mulle-nat opened this issue Dec 18, 2019 · 4 comments · May be fixed by #197
Open

Problems parsing number with JSMN_STRICT is defined #177

mulle-nat opened this issue Dec 18, 2019 · 4 comments · May be fixed by #197

Comments

@mulle-nat
Copy link

If you define JSMN_STRICT, then parsing a simple number doesn't work anymore (it does if you undefine JSMN_STRICT):

#define JSMN_STRICT
#include "jsmn.h"
#include <stdio.h>
#include <string.h>


static char  *json = "1";


int main( void)
{
   jsmn_parser   p;
   jsmntok_t     t[128];
   int           r;

   jsmn_init( &p);
   r = jsmn_parse(&p, json, strlen( json), t, 128);
   if( r < 0) 
   {
      printf("Failed to parse JSON: %d\n", r);
      return 1;
   }
   return( 0);
}

This will bail with error 2.

@pt300
Copy link
Collaborator

pt300 commented Dec 18, 2019

Currently JSMN does not allow anything else than object or array as the root value. This is going to be fixed in the future.

@mulle-nat
Copy link
Author

Well it does work, if you don't define JSMN_STRICT though. So your comment isn't entirely correct.

@pt300
Copy link
Collaborator

pt300 commented Dec 19, 2019

Well, yeah. The non strict mode is.... special. I'd advice against using it personally. In future version it will be either gone or replaced by mode that implements proper standards.

@mulle-nat
Copy link
Author

Actually I kinda like the non-strict mode, as I am using jsmn more as a tokenizer and do the verification f.e. of floating point numbers or "true" vs. "thanks" at a later stage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants