/* JSONPath 0.8.5 - XPath for JSON * * Copyright (c) 2007 Stefan Goessner (goessner.net) * Licensed under the MIT (MIT-LICENSE.txt) licence. * * Proposal of Chris Zyp goes into version 0.9.x * Issue 7 resolved */ function jsonPath(obj, expr, arg) { var P = { resultType: arg && arg.resultType || "VALUE", result: [], normalize: function(expr) { var subx = []; return expr.replace(/[\['](\??\(.*?\))[\]']|\['(.*?)'\]/g, function($0,$1,$2){return "[#"+(subx.push($1||$2)-1)+"]";}) /* http://code.google.com/p/jsonpath/issues/detail?id=4 */ .replace(/'?\.'?|\['?/g, ";") .replace(/;;;|;;/g, ";..;") .replace(/;$|'?\]|'$/g, "") .replace(/#([0-9]+)/g, function($0,$1){return subx[$1];}); }, asPath: function(path) { var x = path.split(";"), p = "$"; for (var i=1,n=x.length; i