********************************************************************** This is YAJL 2. For the legacy version of YAJL see https://github.com/lloyd/yajl/tree/1.x ********************************************************************** Welcome to Yet Another JSON Library (YAJL) ## Why does the world need another C library for parsing JSON? Good question. In a review of current C JSON parsing libraries I was unable to find one that satisfies my requirements. Those are, 0. written in C 1. portable 2. robust -- as close to "crash proof" as possible 3. data representation independent 4. fast 5. generates verbose, useful error messages including context of where the error occurs in the input text. 6. can parse JSON data off a stream, incrementally 7. simple to use 8. tiny Numbers 3, 5, 6, and 7 were particularly hard to find, and were what caused me to ultimately create YAJL. This document is a tour of some of the more important aspects of YAJL. ## YAJL is Free. Permissive licensing means you can use it in open source and commercial products alike without any fees. My request beyond the licensing is that if you find bugs drop me a email, or better yet, fork and fix. Porting YAJL should be trivial, the implementation is ANSI C. If you port to new systems I'd love to hear of it and integrate your patches. ## YAJL is data representation independent. BYODR! Many JSON libraries impose a structure based data representation on you. This is a benefit in some cases and a drawback in others. YAJL uses callbacks to remain agnostic of the in-memory representation. So if you wish to build up an in-memory representation, you may do so using YAJL, but you must bring the code that defines and populates the in memory structure. This also means that YAJL can be used by other (higher level) JSON libraries if so desired. ## YAJL supports stream parsing This means you do not need to hold the whole JSON representation in textual form in memory. This makes YAJL ideal for filtering projects, where you're converting YAJL from one form to another (i.e. XML). The included JSON pretty printer is an example of such a filter program. ## YAJL is fast Minimal memory copying is performed. YAJL, when possible, returns pointers into the client provided text (i.e. for strings that have no embedded escape chars, hopefully the common case). I've put a lot of effort into profiling and tuning performance, but I have ignored a couple possible performance improvements to keep the interface clean, small, and flexible. My hope is that YAJL will perform comparably to the fastest JSON parser out there. YAJL should impose both minimal CPU and memory requirements on your application. ## YAJL is tiny. Fat free. No whip. enjoy, Lloyd - July, 2007
Compilation is failing for me on 64 bit Ubuntu (SliceHost):
test case: 'cases/integers.json': --- cases/integers.json.gold 2009-04-24 21:32:45.000000000 +0000 +++ cases/integers.json.test 2009-05-14 22:50:49.000000000 +0000 @@ -10,5 +10,6 @@ integer: -123456789 integer: 2147483647 integer: -2147483647 -parse error: integer overflow +integer: 2147483648 +array close ']' memory leaks: 0 FAILURE
If using custom allocation, realloc might pass in the old ptr in order to copy the old ptr to new one.
i first opened this issue for twitter-stream api: http://github.com/intridea/tweetstream/issues#issue/5
and it was suggested that maybe the cause is in yajl. when twitter returns id in json, the value is correct, but id field (in the hash) is -1.
It would be really handy to have a yajl.pc pkg-config file installed with libyajl.
hello i have reported and issue when installing a gem script (visage) and the author asked me to report the problem here. here is the original issue : https://github.com/auxesis/visage/issues/124 and here is the installation error :
# gem install visage-app
Building native extensions. This could take a while...
ERROR: Error installing visage-app:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
creating Makefile
make
compiling yajl_ext.c
yajl_ext.c: In function ‘yajl_encode_part’:
yajl_ext.c:117:21: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
yajl_ext.c: In function ‘rb_yajl_parser_parse’:
yajl_ext.c:442:17: warning: variable ‘stat’ set but not used [-Wunused-but-set-variable]
compiling yajl_lex.c
compiling yajl_encode.c
compiling yajl.c
compiling yajl_parser.c
compiling yajl_alloc.c
compiling yajl_gen.c
compiling yajl_buf.c
compiling yajl_version.c
linking shared-object yajl/yajl.so
make install
/usr/bin/install -c -m 0755 yajl.so /var/lib/gems/1.9.1/gems/yajl-ruby-1.1.0/lib/yajl
installing default yajl libraries
Gem files will remain installed in /var/lib/gems/1.9.1/gems/yajl-ruby-1.1.0 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/yajl-ruby-1.1.0/ext/yajl/gem_make.out
(Sorry, I accidentally closed the original issue)
The functions strtod() (used in yajl_parser) and sprintf() (yajl_gen) are locale-dependent and thus cannot be reliably used to convert JSON values. The only reasonable solution I found to this was using setlocale() to insert the "C" locale. However, this can introduce side-effects, so I locally set and then restore it, like this:
char oldLocale; / Example for converting doubles / oldLocale = setlocale(LC_ALL, NULL); / saving old locale / setlocale(LC_ALL, "C"); / ensuring POSIX locale / sprintf(i, "%g", number); / now the conversion works as expected / setlocale(LC_ALL, oldLocale); / restoring locale */
This is, however, probably an inefficient quick fix. The locale should be set before starting the parsing/generation phases and restored at the end, if this does not affect string conversion.
yajl headers are supposed to be installed straight into $PREFIX/include/yajl and they're supposed to be included as <yajl/yajl_something.h>, according to the documentation.
However, pkg-config returns CFLAGS as $PREFIX/include/yajl and that breaks build because "#include <yajl/yajl_something.h>" can't find the header.
This is a problem if $PREFIX is different from /usr or other include directory that's used implicitly (which is a case on macOS with homebrew, where every package has its own $PREFIX).
The documentation mentioned nothing about data ownership. Should I free memory? When should I free it? Is the memory automatically freed by yajl?
Fixed utf-8 output corrupted with truncated surrogates pairs.
As an example, the \uDBFF💀 sequence would produce "?" and then a truncated version of "💀" which would result in invalid-UTF-8.
There is a small typo in src/api/yajl_parse.h.
Should read occurred
rather than occured
.
In yajl_parser.c, on line 253, we pass yajl_buf_data(hand->decodeBuf) to the callback instead of the usual buffer "buf". As this points to another memory location, the callback receive 2 buffers that are located in another space. Concrete problem: in ModSecurity, we use the callback to get the decoded value of the string and we calculate the offset of a variable value in order to mask it in the log. In the callback, when the JSON is decoded, we receive another location than the original one and we cannot calculate the offset.
We should perform this trivial change: if (yajl_string_decode(hand->decodeBuf, buf, bufLen) < 0) return yajl_status_error;
- _CC_CHK(hand->callbacks->yajl_string(hand->ctx, yajl_buf_data(hand->decodeBuf),yajl_buf_len(hand->decodeBuf))); +bufLen = yajl_buf_len(hand->decodeBuf); +strncpy(buf, yajl_buf_data(hand->decodeBuf), bufLen); +_CC_CHK(hand->callbacks->yajl_string(hand->ctx, buf, bufLen));
Note that on line 393, bufLen & buf are correctly updated after yajl_string_decode()
Hi, Is the yajl component being maintained? It seems like it hasn't been updated for a long time. ^_^