Closed selik closed 12 years ago
http://forums.mudlet.org/viewtopic.php?f=7&t=2183
"On further inspection it appears that these functions are no longer defined in yajl 2.0. I think yajl_parse_complete was just renamed to yajl_complete_parse, while yajl_gen_alloc2 was removed, with the equivalent functionality provided elsewhere."
That's a bummer :-(. I want to keep ijson working out of the box on recent(-ish) Ubuntu and it still has yajl 1.x in repositories. I'm not sure what's the best way to move forward here. I could probably make a yajl2-specific branch for that. The problem with non-master branches is that they're pretty much undiscoverable for users
BTW, there's already a branch "buffered" with pure python parsing implementation that doesn't depend on yajl. It's obviously slower under CPython but is on par with yajl-powered code under PyPy.
The "buffered" branch works just fine, though it also refers to README.txt in the setup script. You're right that non-master branches get ignored most of the time.
Non-sequitur: why not provide a function that iterates through all top-level objects in the JSON file? The function items(file, prefix)
requires the user to know the structure of the JSON file, which isn't always true. Also, how would one handle an item that doesn't have a prefix (ex: https://gist.github.com/2017462)?
Just specify an empty string as a prefix for the top-level object (and it's always only a single one). So, basically, this is the equivalent of the usual "load everything" function:
def load(f):
return list(ijson.items(f, ''))[0]
Perhaps it would be good to set an empty string as the default for the prefix parameter?
def items(file, prefix = ''):
...
Nah… I don't think so. Default parameters are good for common use-cases, whereas this one is actually the exact opposite of the iterative parsing that ijson is good for, it just parses the whole document as any other parsers. What might be useful though is to have functions load()
and loads()
as a compatibility interface with the standard json
module.
A quick update. Another person (@sashka) wanted to use ijson with yajl2 so we decided to refactor ijson to support several backends and he volunteered to make a backend for yajl2. The backend structure is already in place so you can already switch back to the master branch and use import ijson.backends.python as ijson
to use the pure python backend.
Implemented yajl2 backend and guessing logic that finds whatever version of yajl is available in the system falling back to pure Python backend if neither is found. So all of these should always work in the system with yajl2 installed:
import ijson
import ijson.backends.yajl2 as ijson
import ijson.backends.python as ijson
I get an AttributeError when parsing a json file from GitHub Archive.
I installed
yajl
with Homebrew. It looks like it uses Yajl version 2.0.4. I installedijson
from source hosted here on GitHub withpython setup.py install
. This appears to be version 0.8.0. I'm using Python version 2.7.3, running iPython installed from source a couple days ago.Code
Output
If I comment out line 19 in lib.py
Then the same code causes the ipython notebook to tell me the kernel crashed and when run in ipython console gives a segmentation fault.
The seg fault makes sense if setting the type of yajl_gen_alloc2 did something useful
Just in case, is this possibly related to the way GitHub Archive does not delimit its objects (https://github.com/igrigorik/githubarchive.org/issues/9)?