Skip to content

Instantly share code, notes, and snippets.

@emilbayes
emilbayes / json-pointer.js
Created March 10, 2015 14:57
Minimalistic JSON Pointer (RFC 6901) implementation. Does not support URI Fragments, but otherwise compliant
'use strict';
exports.get = function(document, pointer) {
//Empty pointer references the whole document
if(pointer === '') return document;
//Split the pointer into reference tokens and unescape
var referenceTokens = pointer.slice(1).split('/').map(unescape);
//Decent down the object iteratively
return referenceTokens.reduce(function(object, token) {