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

Difference between MJSON and Frozen? #65

Open
Harvie opened this issue Jun 9, 2021 · 3 comments
Open

Difference between MJSON and Frozen? #65

Harvie opened this issue Jun 9, 2021 · 3 comments

Comments

@Harvie
Copy link

Harvie commented Jun 9, 2021

Hello,
cessanta hosts two JSON libraries:
https://github.com/cesanta/mjson/ (~1.0 kLoC)
https://github.com/cesanta/frozen/ (~1.5 kLoC)

Both seem to be tiny. Is there any reccomendation on which library to use for specific use cases?
I think it might be useful to cross-reference and mention this in READMEs of both libraries, so users can make better decisions when choosing between the two.

Thanks.

@cpq
Copy link
Member

cpq commented Sep 5, 2021

  1. Different way for scanning values: frozen scans using {a: %d} format, mjson uses jsonpath $.a
  2. mjson supports a bit less conversion specifiers
  3. mjson does not use libc printf as a dependency - it never falls back to snprintf(). It implements its own low level printing routines, like mjson_print_dbl(), and therefore works on a wider set of platforms - even where floating point support in libc is absent
  4. mjson has a very lightweight built-in json-rpc API
  5. mjson is MIT, frozen in Apache2

We'd recommend using mjson - unless you're using Mongoose OS, where frozen is built-in.

@Harvie
Copy link
Author

Harvie commented Sep 5, 2021

mjson does not use libc printf as a dependency - it never falls back to snprintf(). It implements its own low level printing routines, like mjson_print_dbl().

This is interresting given the fact that snprintf() (any any of calls from *printf() family) is not async signal safe (see man signal-safety). Does this make mjson async signal safe? This basicaly means that such function (eg. printf) shares some buffer between threads and uses mutex to serialize access to it, so if one of the threads get interrupted (by signal, or ISR) the other threads can become deadlocked because mutex is left locked by thread which is no longer running.

@cpq
Copy link
Member

cpq commented Sep 6, 2021

@Harvie mjson does not use any shared / static buffers or variables. It is safe to use it from multiple threads/tasks.

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

No branches or pull requests

2 participants