diff --git a/README.markdown b/README.markdown index ef467db..cf87e05 100755 --- a/README.markdown +++ b/README.markdown @@ -10,7 +10,6 @@ This library converts XML into a customizable data object. The data object conta XMLtoJSON requires: * jQuery (> 1.5) -* John's Resig Simple-Inheritance ## Usage diff --git a/example/dependencies/application.js b/example/dependencies/application.js index 87f0d9b..5eeb6f6 100755 --- a/example/dependencies/application.js +++ b/example/dependencies/application.js @@ -18,7 +18,7 @@ $(document).ready(function(){ } else{ $('#result').attr('value', js_beautify(JSON.stringify(data.json))).show(); - $('#time').html('Result (' + data.duration + ')').show(); + $('#time').html('Result for data.json (' + data.duration + ')').show(); $('#time, #result').appendTo($(this).parent()); return false; } diff --git a/example/dependencies/simple-inheritance.js b/example/dependencies/simple-inheritance.js deleted file mode 100755 index 46d7fb8..0000000 --- a/example/dependencies/simple-inheritance.js +++ /dev/null @@ -1,63 +0,0 @@ -/* Simple JavaScript Inheritance - * By John Resig http://ejohn.org/ - * MIT Licensed. - */ -// Inspired by base2 and Prototype -(function(){ - var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; - // The base Class implementation (does nothing) - this.Class = function(){}; - - // Create a new Class that inherits from this class - Class.extend = function(prop) { - var _super = this.prototype; - - // Instantiate a base class (but only create the instance, - // don't run the init constructor) - initializing = true; - var prototype = new this(); - initializing = false; - - // Copy the properties over onto the new prototype - for (var name in prop) { - // Check if we're overwriting an existing function - prototype[name] = typeof prop[name] == "function" && - typeof _super[name] == "function" && fnTest.test(prop[name]) ? - (function(name, fn){ - return function() { - var tmp = this._super; - - // Add a new ._super() method that is the same method - // but on the super-class - this._super = _super[name]; - - // The method only need to be bound temporarily, so we - // remove it when we're done executing - var ret = fn.apply(this, arguments); - this._super = tmp; - - return ret; - }; - })(name, prop[name]) : - prop[name]; - } - - // The dummy class constructor - function Class() { - // All construction is actually done in the init method - if ( !initializing && this.init ) - this.init.apply(this, arguments); - } - - // Populate our constructed prototype object - Class.prototype = prototype; - - // Enforce the constructor to be what we expect - Class.constructor = Class; - - // And make this class extendable - Class.extend = arguments.callee; - - return Class; - }; -})(); \ No newline at end of file diff --git a/example/index.html b/example/index.html index fb7065f..29ce05e 100755 --- a/example/index.html +++ b/example/index.html @@ -9,7 +9,6 @@ - diff --git a/lib/jquery.xmltojson.js b/lib/jquery.xmltojson.js index 1797a0f..89adfc9 100755 --- a/lib/jquery.xmltojson.js +++ b/lib/jquery.xmltojson.js @@ -3,7 +3,6 @@ * @version 0.1 * @author Sebastian Kranz * requires jQuery - * requires John's Resig Simple-Inheritance */ /** @@ -26,11 +25,11 @@ * log: Enable or disable output on console for errors and converting problems */ -var XMLtoJSON = Class.extend({ - - // Initialize JSON conversion - init: function(options){ +var XMLtoJSON = function(options){ + // Define Initialization + this.init = function(){ + this.xml = false, this.document = false; this.json = {}; @@ -71,13 +70,13 @@ var XMLtoJSON = Class.extend({ // Modify JSON this.modifyJSON(); } - + // Time taken this.duration = new Date() - this.duration + ' ms'; - }, + } // Get XML as text from a external url - receiveXML: function(){ + this.receiveXML = function(){ var url = this.options.url, response; $.ajax({ @@ -97,10 +96,10 @@ var XMLtoJSON = Class.extend({ this.throwError('Cannot receive XML from ' + this.options.url); if(this.options.fallback != null) this.options.fallback({message : 'Cannot receive XML from ' + this.options.url, code : 404}); } - }, + } // Parse XML - parseXML: function(){ + this.parseXML = function(){ this.xml = this.xml.replace(/^[\s\n\r\t]*[<][\?][xml][^<^>]*[\?][>]/, ''); if(window.ActiveXObject){ this.document = new ActiveXObject('Microsoft.XMLDOM'); @@ -112,11 +111,11 @@ var XMLtoJSON = Class.extend({ this.document = this.document.parseFromString(this.xml, 'application/xml'); } if(!this.xml || !this.document) this.throwError('Cannot parse XML'); - }, + } // Convert XML to JSON (inner closure, recursive) // Increase performance by replace jQuery.each with native Javascript for-loop (should be 2-3 times faster, depeding von the Document size) - convertXML: function(){ + this.convertXML = function(){ var _this = this; (function evaluate(node, obj, options, ns) { @@ -221,10 +220,10 @@ var XMLtoJSON = Class.extend({ } })(this.document, this.json, this.options, {}); // Execute - }, + } // Modify JSON - modifyJSON : function(){ + this.modifyJSON = function(){ var _this = this, attributeIdentifier = this.options.attributeIdentifier; $.each(this.options.modify, function(url, modified){ @@ -273,10 +272,10 @@ var XMLtoJSON = Class.extend({ } } }); - }, + } // Create a all parts of a non existing node tree - createNodes : function(string){ + this.createNodes = function(string){ var _this = this; var node = this.get(string, false); if(node) return; @@ -292,10 +291,10 @@ var XMLtoJSON = Class.extend({ if(!part) eval('_this.json.' + partUrl + '={}'); checkNode(url, index+1); })(string, 0); - }, + } // Get JSON by a full identifiable String splitted by '.' - get : function(path, log){ + this.get = function(path, log){ var array = '', root = null, log = (log == false) ? false : true; @@ -315,10 +314,10 @@ var XMLtoJSON = Class.extend({ if(log == true) this.throwError('Invalid path ' + path); } return (root) ? root : (log == true ? this.throwError('Could not access ' + path) : null); - }, + } // Find each JSON element by a given String splitted by '.' and additional conditions - find : function(path, condition){ + this.find = function(path, condition){ var _this = this, parts = []; // Get children from path @@ -457,10 +456,10 @@ var XMLtoJSON = Class.extend({ } } return (!parts) ? [] : parts; - }, + } // Remove JSON by a given String splitted by '.' - remove : function(string){ + this.remove = function(string){ if(this.get(string)){ eval('delete this.json.' + string); if(string.match(/\[*.\]$/)){ @@ -472,10 +471,10 @@ var XMLtoJSON = Class.extend({ eval('_this.json.' + string.replace(/\[*.\]$/, '') + ' = filterNull'); } } - }, + } // Detect type for string values of true, false, integer and null - detectTypes : function(string){ + this.detectTypes = function(string){ if(string.match(/^true$/i)){ return true } @@ -491,10 +490,10 @@ var XMLtoJSON = Class.extend({ else{ return string; } - }, + } // Log specific error message - throwError: function(msg){ + this.throwError = function(msg){ if(this.options.log){ if(!window.console){ // Add log method to window.console @@ -505,5 +504,8 @@ var XMLtoJSON = Class.extend({ console.log(msg); } } + + // Initialize + this.init(); -}); \ No newline at end of file +}; \ No newline at end of file diff --git a/lib/jquery.xmltojson.min.js b/lib/jquery.xmltojson.min.js index 5a64b3a..8ff4130 100755 --- a/lib/jquery.xmltojson.min.js +++ b/lib/jquery.xmltojson.min.js @@ -1 +1 @@ -var XMLtoJSON=Class.extend({init:function(a){this.xml=false,this.document=false;this.json={};this.duration=new Date();this.options=$.extend({url:false,xmlString:false,namespaces:false,valueIdentifier:"$",attributeIdentifier:"_",emptyValuesAsNull:false,modify:{},clearEmptyNodes:false,cache:false,detectTypes:false,filter:null,fallback:null,log:false},a);if(this.options.url){this.receiveXML()}if(this.options.xmlString){this.xml=this.options.xmlString}if(this.xml){this.parseXML();this.convertXML();if(this.options.fallback!=null&&(this.json=={}||this.json.parsererror)){this.options.fallback({message:"XML is invalid",code:500})}this.modifyJSON()}this.duration=new Date()-this.duration+" ms"},receiveXML:function(){var b=this.options.url,a;$.ajax({type:"GET",url:b,async:false,dataType:"text",cache:this.options.cache,complete:function(c){if(c.responseText){a=c.responseText.replace(/^\s+/,"")}}});if(a){this.xml=a}else{this.throwError("Cannot receive XML from "+this.options.url);if(this.options.fallback!=null){this.options.fallback({message:"Cannot receive XML from "+this.options.url,code:404})}}},parseXML:function(){this.xml=this.xml.replace(/^[\s\n\r\t]*[<][\?][xml][^<^>]*[\?][>]/,"");if(window.ActiveXObject){this.document=new ActiveXObject("Microsoft.XMLDOM");this.document.async=false;this.document.loadXML(this.xml)}else{this.document=new DOMParser();this.document=this.document.parseFromString(this.xml,"application/xml")}if(!this.xml||!this.document){this.throwError("Cannot parse XML")}},convertXML:function(){var b=this;(function a(d,h,n,j){var f=n.valueIdentifier,m=n.attributeIdentifier;if(d.nodeType===9){$.each(d.childNodes,function(){a(this,h,n,j)})}else{if(d.nodeType===1){var g=j[f]?{valueIdentifier:true}:{};var k=d.nodeName;var c=n.namespaces==true?true:false;var i={};if(k.indexOf(":")!=-1){g[k.substr(0,k.indexOf(":"))]=true}$.each(d.attributes,function(){var o=this.nodeName;var p=this.nodeValue;if(b.options.filter){p=b.options.filter(p)}if(b.options.detectTypes){p=b.detectTypes(p)}if(o==="xmlns"){j[f]=p;g[f]=true}else{if(o.indexOf("xmlns:")===0){j[o.substr(o.indexOf(":")+1)]=p}else{if(o.indexOf(":")!=-1){i[m+o]=p;g[o.substr(0,o.indexOf(":"))]=true}else{if(b.options.emptyValuesAsNull&&(p===""||p===null)){i[m+o]=null}else{i[m+o]=p}}}}});var e=c?j:g;$.each(e,function(o,p){if(e.hasOwnProperty(o)){i[m+"xmlns"]=i[m+"xmlns"]||{};i[m+"xmlns"][o]=p}});if(h[k] instanceof Array){h[k].push(i)}else{if(h[k] instanceof Object){h[k]=[h[k],i]}else{h[k]=i}}if(b.options.emptyValuesAsNull&&d.childNodes.length==0){h[k]=null}$.each(d.childNodes,function(){a(this,i,n,j)})}else{if(d.nodeType===3){var l=d.nodeValue;if(!l.match(/[\S]+/)){return}if(b.options.filter){l=b.options.filter(l)}if(b.options.detectTypes){l=b.detectTypes(l)}if(h[f] instanceof Array){h[f].push(l)}else{if(h[f] instanceof Object){h[f]=[h[f],l]}else{h[f]=l}}}}}})(this.document,this.json,this.options,{})},modifyJSON:function(){var _this=this,attributeIdentifier=this.options.attributeIdentifier;$.each(this.options.modify,function(url,modified){var all=url.match(/\.\*$/)?true:false;var url=all?url.replace(/\.\*$/,""):url;var content=_this.find(url);if(content){var newParent=modified.replace(/\.[^\.]*$/,"");if(modified.split(".").length>1){var newNode=newParent+'["'+modified.split(".")[modified.split(".").length-1]+'"]'}else{var newNode=modified}if(!all){_this.remove(url)}if(newParent.split(".").length>1){_this.createNodes(newParent)}_this.createNodes(modified);if(all){newNode=newNode.match(/\[\"\"\]/)?"":(newNode+".");$.each(content,function(key,value){if(key[0]!=attributeIdentifier){eval("_this.json."+newNode+key+" = value")}});$.each(_this.find(url),function(key,value){if(key[0]!=attributeIdentifier){_this.remove(url+"."+key)}})}else{eval("_this.json."+newNode+" = content")}if(_this.options.clearEmptyNodes){var parentNode=all?_this.find(url):_this.find(url.replace(/\.[^\.]*$/,""));var emptyNodes=true;$.each(parentNode,function(key,value){if(value instanceof Object){var children=0;for(var i in value){children++}if(children>1||children==1&&!_this.options.namespaces){return emptyNodes=false}}if(key[0]!=attributeIdentifier){return emptyNodes=false}});if(emptyNodes){all?_this.remove(url):_this.remove(url.replace(/\.[^\.]*$/,""))}}}})},createNodes:function(string){var _this=this;var node=this.get(string,false);if(node){return}(function checkNode(url,index){var current=url.split(".")[index];if(!current){return}var partUrl=[];for(var i=0;i<=index;i++){partUrl.push(url.split(".")[i])}partUrl=partUrl.join(".");var part=_this.get(partUrl,false);if(!part){eval("_this.json."+partUrl+"={}")}checkNode(url,index+1)})(string,0)},get:function(path,log){var array="",root=null,log=(log==false)?false:true;path=path.replace(/^\./,"");$.each(path.split("."),function(){if(this.match(/\[*.\]$/)){array+='["'+this.split("[")[0]+'"]'+this.match(/\[*.\]$/)[0]}else{array+='["'+this+'"]'}});try{root=eval("this.json"+array)}catch(e){if(log==true){this.throwError("Invalid path "+path)}}return(root)?root:(log==true?this.throwError("Could not access "+path):null)},find:function(path,condition){var _this=this,parts=[];function children(root,path){var url="",parts=[];$.each(path.split("."),function(i){var tempParts=[];if(i==0){url=this;tempParts=root}else{url+="."+this;if(this.match(/\[*.\]$/)){tempParts=parts[this.split("[")[0]][this.match(/\[*.\]$/)[0].replace(/[\[|\]]/g,"")]}else{if(parts instanceof Array){var part=this;$.each(parts,function(){if(this instanceof Array){$.each(this,function(){if(this[part]!=undefined){tempParts.push(this[part])}})}else{if(this[part]!=undefined){tempParts.push(this[part])}}})}else{tempParts=parts[this]}}}if(!tempParts||tempParts.length==0){_this.throwError("Invalid path "+url);parts=[];return false}else{parts=tempParts}});return parts}if(path.split(".")[0].match(/\[*.\]$/)){var index=path.split(".")[0].match(/\[*.\]$/)[0].replace(/[\[|\]]/g,"");var root=this.json[path.split(".")[0].replace(/\[.*\]/,"")][index]}else{var root=this.json[path.split(".")[0]]}parts=children(root,path);if(condition){function match(element,operator,rule){if(element&&operator&&rule){if(operator==="=~"){var options="";if(rule.match(/^\/.*/)&&rule.match(/\/.$/)){options=rule[rule.length-1];rule=rule.substring(0,rule.length-1)}rule=rule.replace(/^\//,"").replace(/\/$/,"");return(element.toString().match(new RegExp(rule,options)))?true:false}else{if(operator==="=="||operator==="!="){return(eval("element.toString()"+operator+"rule"))?true:false}else{rule=parseInt(rule);element=parseInt(element);return(eval("element"+operator+"rule"))?true:false}}}}var validParts=[],rule=condition.replace(/^.*(==|\>=|\<=|\>|\<|!=|=~)/,""),subpath=condition.replace(/(==|\>=|\<=|\>|\<|!=|=~).*$/,"").replace(/\s$/,""),operator=condition.replace(rule,"").replace(subpath,"").replace(/\s/,""),element=subpath.split(".")[subpath.split(".").length-1];if(element===subpath){subpath=null}if(parts instanceof Array){if(!subpath){$.each(parts,function(){if(match(this[element],operator,rule)){validParts.push(this)}})}else{$.each(parts,function(){var currentChildren=children(this,"."+subpath),part=this;if(currentChildren instanceof Array){$.each(currentChildren,function(){if(match(this,operator,rule)){validParts.push(part);return false}})}else{if(match(currentChildren,operator,rule)){validParts.push(this)}}})}parts=validParts}else{if(!subpath){if(!match(parts[element],operator,rule)){parts=null}}else{var currentChildren=children(parts,"."+subpath);var currentChildren=children(parts,"."+subpath),valid=false;if(currentChildren instanceof Array){$.each(currentChildren,function(){if(match(this,operator,rule)){valid=true;return false}})}else{if(match(currentChildren,operator,rule)){valid=true}}parts=valid?parts:null}}}return(!parts)?[]:parts},remove:function(string){if(this.get(string)){eval("delete this.json."+string);if(string.match(/\[*.\]$/)){var _this=this;var filterNull=$.grep(eval("_this.json."+string.replace(/\[*.\]$/,"")),function(n,i){return(n)});eval("_this.json."+string.replace(/\[*.\]$/,"")+" = filterNull")}}},detectTypes:function(a){if(a.match(/^true$/i)){return true}else{if(a.match(/^false$/i)){return false}else{if(a.match(/^null|NaN|nil|undefined$/i)){return null}else{if(a.match(/^[0-9]*$/i)){return parseInt(a)}else{return a}}}}},throwError:function(a){if(this.options.log){if(!window.console){window.console={log:function(b){alert(b)}}}console.log(a)}}}); \ No newline at end of file +var XMLtoJSON=function(options){this.init=function(){this.xml=false,this.document=false;this.json={};this.duration=new Date();this.options=$.extend({url:false,xmlString:false,namespaces:false,valueIdentifier:"$",attributeIdentifier:"_",emptyValuesAsNull:false,modify:{},clearEmptyNodes:false,cache:false,detectTypes:false,filter:null,fallback:null,log:false},options);if(this.options.url){this.receiveXML()}if(this.options.xmlString){this.xml=this.options.xmlString}if(this.xml){this.parseXML();this.convertXML();if(this.options.fallback!=null&&(this.json=={}||this.json.parsererror)){this.options.fallback({message:"XML is invalid",code:500})}this.modifyJSON()}this.duration=new Date()-this.duration+" ms"};this.receiveXML=function(){var url=this.options.url,response;$.ajax({type:"GET",url:url,async:false,dataType:"text",cache:this.options.cache,complete:function(data){if(data.responseText){response=data.responseText.replace(/^\s+/,"")}}});if(response){this.xml=response}else{this.throwError("Cannot receive XML from "+this.options.url);if(this.options.fallback!=null){this.options.fallback({message:"Cannot receive XML from "+this.options.url,code:404})}}};this.parseXML=function(){this.xml=this.xml.replace(/^[\s\n\r\t]*[<][\?][xml][^<^>]*[\?][>]/,"");if(window.ActiveXObject){this.document=new ActiveXObject("Microsoft.XMLDOM");this.document.async=false;this.document.loadXML(this.xml)}else{this.document=new DOMParser();this.document=this.document.parseFromString(this.xml,"application/xml")}if(!this.xml||!this.document){this.throwError("Cannot parse XML")}};this.convertXML=function(){var _this=this;(function evaluate(node,obj,options,ns){var valueIdentifier=options.valueIdentifier,attributeIdentifier=options.attributeIdentifier;if(node.nodeType===9){$.each(node.childNodes,function(){evaluate(this,obj,options,ns)})}else{if(node.nodeType===1){var activeNamespace=ns[valueIdentifier]?{valueIdentifier:true}:{};var nodeName=node.nodeName;var addNamespaces=options.namespaces==true?true:false;var current={};if(nodeName.indexOf(":")!=-1){activeNamespace[nodeName.substr(0,nodeName.indexOf(":"))]=true}$.each(node.attributes,function(){var name=this.nodeName;var value=this.nodeValue;if(_this.options.filter){value=_this.options.filter(value)}if(_this.options.detectTypes){value=_this.detectTypes(value)}if(name==="xmlns"){ns[valueIdentifier]=value;activeNamespace[valueIdentifier]=true}else{if(name.indexOf("xmlns:")===0){ns[name.substr(name.indexOf(":")+1)]=value}else{if(name.indexOf(":")!=-1){current[attributeIdentifier+name]=value;activeNamespace[name.substr(0,name.indexOf(":"))]=true}else{if(_this.options.emptyValuesAsNull&&(value===""||value===null)){current[attributeIdentifier+name]=null}else{current[attributeIdentifier+name]=value}}}}});var namespace=addNamespaces?ns:activeNamespace;$.each(namespace,function(key,value){if(namespace.hasOwnProperty(key)){current[attributeIdentifier+"xmlns"]=current[attributeIdentifier+"xmlns"]||{};current[attributeIdentifier+"xmlns"][key]=value}});if(obj[nodeName] instanceof Array){obj[nodeName].push(current)}else{if(obj[nodeName] instanceof Object){obj[nodeName]=[obj[nodeName],current]}else{obj[nodeName]=current}}if(_this.options.emptyValuesAsNull&&node.childNodes.length==0){obj[nodeName]=null}$.each(node.childNodes,function(){evaluate(this,current,options,ns)})}else{if(node.nodeType===3){var value=node.nodeValue;if(!value.match(/[\S]+/)){return}if(_this.options.filter){value=_this.options.filter(value)}if(_this.options.detectTypes){value=_this.detectTypes(value)}if(obj[valueIdentifier] instanceof Array){obj[valueIdentifier].push(value)}else{if(obj[valueIdentifier] instanceof Object){obj[valueIdentifier]=[obj[valueIdentifier],value]}else{obj[valueIdentifier]=value}}}}}})(this.document,this.json,this.options,{})};this.modifyJSON=function(){var _this=this,attributeIdentifier=this.options.attributeIdentifier;$.each(this.options.modify,function(url,modified){var all=url.match(/\.\*$/)?true:false;var url=all?url.replace(/\.\*$/,""):url;var content=_this.find(url);if(content){var newParent=modified.replace(/\.[^\.]*$/,"");if(modified.split(".").length>1){var newNode=newParent+'["'+modified.split(".")[modified.split(".").length-1]+'"]'}else{var newNode=modified}if(!all){_this.remove(url)}if(newParent.split(".").length>1){_this.createNodes(newParent)}_this.createNodes(modified);if(all){newNode=newNode.match(/\[\"\"\]/)?"":(newNode+".");$.each(content,function(key,value){if(key[0]!=attributeIdentifier){eval("_this.json."+newNode+key+" = value")}});$.each(_this.find(url),function(key,value){if(key[0]!=attributeIdentifier){_this.remove(url+"."+key)}})}else{eval("_this.json."+newNode+" = content")}if(_this.options.clearEmptyNodes){var parentNode=all?_this.find(url):_this.find(url.replace(/\.[^\.]*$/,""));var emptyNodes=true;$.each(parentNode,function(key,value){if(value instanceof Object){var children=0;for(var i in value){children++}if(children>1||children==1&&!_this.options.namespaces){return emptyNodes=false}}if(key[0]!=attributeIdentifier){return emptyNodes=false}});if(emptyNodes){all?_this.remove(url):_this.remove(url.replace(/\.[^\.]*$/,""))}}}})};this.createNodes=function(string){var _this=this;var node=this.get(string,false);if(node){return}(function checkNode(url,index){var current=url.split(".")[index];if(!current){return}var partUrl=[];for(var i=0;i<=index;i++){partUrl.push(url.split(".")[i])}partUrl=partUrl.join(".");var part=_this.get(partUrl,false);if(!part){eval("_this.json."+partUrl+"={}")}checkNode(url,index+1)})(string,0)};this.get=function(path,log){var array="",root=null,log=(log==false)?false:true;path=path.replace(/^\./,"");$.each(path.split("."),function(){if(this.match(/\[*.\]$/)){array+='["'+this.split("[")[0]+'"]'+this.match(/\[*.\]$/)[0]}else{array+='["'+this+'"]'}});try{root=eval("this.json"+array)}catch(e){if(log==true){this.throwError("Invalid path "+path)}}return(root)?root:(log==true?this.throwError("Could not access "+path):null)};this.find=function(path,condition){var _this=this,parts=[];function children(root,path){var url="",parts=[];$.each(path.split("."),function(i){var tempParts=[];if(i==0){url=this;tempParts=root}else{url+="."+this;if(this.match(/\[*.\]$/)){tempParts=parts[this.split("[")[0]][this.match(/\[*.\]$/)[0].replace(/[\[|\]]/g,"")]}else{if(parts instanceof Array){var part=this;$.each(parts,function(){if(this instanceof Array){$.each(this,function(){if(this[part]!=undefined){tempParts.push(this[part])}})}else{if(this[part]!=undefined){tempParts.push(this[part])}}})}else{tempParts=parts[this]}}}if(!tempParts||tempParts.length==0){_this.throwError("Invalid path "+url);parts=[];return false}else{parts=tempParts}});return parts}if(path.split(".")[0].match(/\[*.\]$/)){var index=path.split(".")[0].match(/\[*.\]$/)[0].replace(/[\[|\]]/g,"");var root=this.json[path.split(".")[0].replace(/\[.*\]/,"")][index]}else{var root=this.json[path.split(".")[0]]}parts=children(root,path);if(condition){function match(element,operator,rule){if(element&&operator&&rule){if(operator==="=~"){var options="";if(rule.match(/^\/.*/)&&rule.match(/\/.$/)){options=rule[rule.length-1];rule=rule.substring(0,rule.length-1)}rule=rule.replace(/^\//,"").replace(/\/$/,"");return(element.toString().match(new RegExp(rule,options)))?true:false}else{if(operator==="=="||operator==="!="){return(eval("element.toString()"+operator+"rule"))?true:false}else{rule=parseInt(rule);element=parseInt(element);return(eval("element"+operator+"rule"))?true:false}}}}var validParts=[],rule=condition.replace(/^.*(==|\>=|\<=|\>|\<|!=|=~)/,""),subpath=condition.replace(/(==|\>=|\<=|\>|\<|!=|=~).*$/,"").replace(/\s$/,""),operator=condition.replace(rule,"").replace(subpath,"").replace(/\s/,""),element=subpath.split(".")[subpath.split(".").length-1];if(element===subpath){subpath=null}if(parts instanceof Array){if(!subpath){$.each(parts,function(){if(match(this[element],operator,rule)){validParts.push(this)}})}else{$.each(parts,function(){var currentChildren=children(this,"."+subpath),part=this;if(currentChildren instanceof Array){$.each(currentChildren,function(){if(match(this,operator,rule)){validParts.push(part);return false}})}else{if(match(currentChildren,operator,rule)){validParts.push(this)}}})}parts=validParts}else{if(!subpath){if(!match(parts[element],operator,rule)){parts=null}}else{var currentChildren=children(parts,"."+subpath);var currentChildren=children(parts,"."+subpath),valid=false;if(currentChildren instanceof Array){$.each(currentChildren,function(){if(match(this,operator,rule)){valid=true;return false}})}else{if(match(currentChildren,operator,rule)){valid=true}}parts=valid?parts:null}}}return(!parts)?[]:parts};this.remove=function(string){if(this.get(string)){eval("delete this.json."+string);if(string.match(/\[*.\]$/)){var _this=this;var filterNull=$.grep(eval("_this.json."+string.replace(/\[*.\]$/,"")),function(n,i){return(n)});eval("_this.json."+string.replace(/\[*.\]$/,"")+" = filterNull")}}};this.detectTypes=function(string){if(string.match(/^true$/i)){return true}else{if(string.match(/^false$/i)){return false}else{if(string.match(/^null|NaN|nil|undefined$/i)){return null}else{if(string.match(/^[0-9]*$/i)){return parseInt(string)}else{return string}}}}};this.throwError=function(msg){if(this.options.log){if(!window.console){window.console={log:function(s){alert(s)}}}console.log(msg)}};this.init()}; \ No newline at end of file