YUI.add("dataschema-json",function(y,e){var r=y.Lang,L=r.isFunction,n=r.isObject,l=r.isArray,m=y.DataSchema.Base,k={getPath:function(e){var r=null,a=[],s=0;if(e)for(s=(r=(e=e.replace(/\[\s*(['"])(.*?)\1\s*\]/g,function(e,r,t){return a[s]=t,".@"+s++}).replace(/\[(\d+)\]/g,function(e,r){return a[s]=0|parseInt(r,10),".@"+s++}).replace(/^\./,"")).split(".")).length-1;0<=s;--s)"@"===r[s].charAt(0)&&(r[s]=a[parseInt(r[s].substr(1),10)]);return r},getLocationValue:function(e,r){for(var t=0,a=e.length;t<a;t++){if(!(n(r)&&e[t]in r)){r=undefined;break}r=r[e[t]]}return r},apply:function(e,r){var t=r,a={results:[],meta:{}};if(!n(r))try{t=y.JSON.parse(r)}catch(s){return a.error=s,a}return n(t)&&e?(a=k._parseResults.call(this,e,t,a),e.metaFields!==undefined&&(a=k._parseMeta(e.metaFields,t,a))):a.error=new Error("JSON schema parse failure"),a},_parseResults:function(e,r,t){var a=k.getPath,s=k.getLocationValue,a=a(e.resultListLocator),a=a?s(a,r)||r[e.resultListLocator]:r;return l(a)?l(e.resultFields)?t=k._getFieldValues.call(this,e.resultFields,a,t):t.results=a:e.resultListLocator&&(t.results=[],t.error=new Error("JSON results retrieval failure")),t},_getFieldValues:function(e,r,t){for(var a,s,n,l,u,i,o,c=[],h=e.length,p=[],f=[],d=[],g=0;g<h;g++)n=(s=e[g]).key||s,u=s.locator||n,(l=k.getPath(u))&&(1===l.length?p.push({key:n,path:l[0]}):f.push({key:n,path:l,locator:u})),(u=L(s.parser)?s.parser:y.Parsers[s.parser+""])&&d.push({key:n,parser:u});for(g=r.length-1;0<=g;--g)if(o={},i=r[g]){for(a=f.length-1;0<=a;--a)l=f[a],k.getLocationValue(l.path,i)===undefined&&k.getLocationValue([l.locator],i)!==undefined?(p.push({key:l.key,path:l.locator}),f.splice(g,1)):o[l.key]=m.parse.call(this,k.getLocationValue(l.path,i),l);for(a=p.length-1;0<=a;--a)o[(l=p[a]).key]=m.parse.call(this,i[l.path]===undefined?i[a]:i[l.path],l);for(a=d.length-1;0<=a;--a)o[n=d[a].key]=d[a].parser.call(this,o[n]),o[n]===undefined&&(o[n]=null);c[g]=o}return t.results=c,t},_parseMeta:function(e,r,t){var a,s;if(n(e))for(a in e)e.hasOwnProperty(a)&&(s=k.getPath(e[a]))&&r&&(t.meta[a]=k.getLocationValue(s,r));else t.error=new Error("JSON meta data retrieval failure");return t}};y.DataSchema.JSON=y.mix(k,m)},"patched-v3.18.4",{requires:["dataschema-base","json"]});