Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Pre-compile pointer? #8

hildjj opened this Issue · 11 comments

3 participants


What do you think about the ability to pre-compile a pointer? This would return a function that might be slightly faster for querying, but slower to create than the current approach. For applications where you're making the same query over and over, this would be a win.


Could you mock up a sample API? I think I like the idea.


I'd be happy to just implement it. I was thinking:

var get = jsonpointer.compile_get('/foo/bar');
var result = get(obj);
var set = jsonpointer.compile_set('/foo/bar');
var result = set(obj, value);

Ah, sounds good. Just as a bikeshed, would something like this work?

var ptr = jsonpointer.compile('/foo/bar');
var result = get(obj, ptr);
var result2 = set(obj, ptr, value);

Hm. How about:

var ptr = jsonpointer.compile('/foo/bar');
var result = ptr(obj);
var result2= ptr(obj, value);

heh, nice, too! :)

My thinking is overloading get() and set() to accept a pointer string or a compiled pointer. To minimise API surface and all. If it is tedious to implement, I am happy with whatever you come up with.


I understand your point, but I'm not sure what the compiled function returns in order to work for both get and set. I'm just testing the above; let's see how you feel about it when you've got something concrete.




Check out this branch: hildjj@d5cdc65


will do in the morning, thanks! :)


I took a different approach that doesn't use eval anymore. I'm happier about the potential attack surface now. hildjj@1c373d5

@marcbachmann marcbachmann referenced this issue

Compose #20


I've merged the compile functionality with the api

var pointer = jsonpointer.compile('/path')
pointer.set(object, value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.