Related
I have a JSON object that I want to change values dynamically with the object that comes from front end(ReactJs) which has same value as the key of that object.here is my JSON object.
var jsonObj = {
"fields": {
"field1": {
"key": "value_1"
},"field2": {
"name": "value_3"
},
"field3":{"accountId":"value_9"},
"field4": "value_2",
"field5": "value_4",
"field6": "value_5",
"field7": {
"value": "value_6"
},
"field8": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "value_7",
"type": "text"
}
]
}
]
}
}
}
This is my other object that comes from React front-end
Obj1 {
value_4: '896',
value_9: '62cbef88ec233f24600c',
value_5: 'Software',
value_7: 'description from front',
value_6: 'test#gmail.com',
value_1: 'TRDSD',
value_2: 'Test sum',
value_8: '',
value_10: '',
value_11: '',
value_12: '',
value_13: '',
value_3: 'TRDSD_incident'
}
What I want is this,
{
"fields": {
"field1": {
"key": "TRDSD"
},"field2": {
"name": "TRDSD_incident"
},
"field3":{"accountId":"62cbef88ec233f24600c"},
"field4": "Test sum",
"field5": "896",
"field6": "Software",
"field7": {
"value": "test#gmail.com"
},
"field8": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "description from front",
"type": "text"
}
]
}
]
}
}
}
Already I achieve this using this function.here what I do is first I take keys that have no nested objects into an array and check for each field.also I have same function for nested object keys and check for each in the same way( value,key,name,accountId). and finally I get the JSON object as I expected.
function usingTree2(obj2, map) {
function traverse2(children) {
for (let item of children) {
if (item && item.field4) {
item.field4 = map[item.field4];
}
if (item && item.field5) {
item.field5 = map[item.field5];
}
if (item && item.field6) {
item.field6 = map[item.field6];
}
if (item && item.field8.content[0].content[0].text) {
item.field8.content[0].content[0].text =
map[item.field8.content[0].content[0].text];
}
if (item && item.children) {
traverse2(item.children);
}
}
}
traverse2(obj2);
return obj2;
}
function usingTree(obj, map) {
function traverse(children) {
for (let item of children) {
if (item && item.key) {
item.key = map[item.key];
} else if (item && item.value) {
item.value = map[item.value];
} else if (item && item.name) {
item.name = map[item.name];
} else if (item && item.accountId) {
item.accountId = map[item.accountId];
} else if (item && item.id) {
item.id = map[item.id];
}
if (item && item.children) {
traverse(item.children);
}
}
}
traverse(obj);
return obj;
}
const map = obj1
var obj = Object.values(jsonObj.fields);
var obj2 = Object.values(jsonObj);
usingTree(obj, map);
usingTree2(obj2, map);
for (let i = 0; i < fieldCount; i ++) {
usingTree(obj, map);
}
for (let i = 0; i < fieldCount; i ++) {
usingTree2(obj2, map);
}
But the problem is fields in JSON object are changing. So instead of checking for each field how can I achieve this dynamically.Of course without using same function twice for nested objects. I know this is not a best way. I am new to Nodejs, so please help me to do this. Hope my question is clear. Thanks in advance.
I have a simple problem but i cann't solve it!!! I have a simple json file with points.. Every single point has coordinates (long,lat) and an id. This file i want to insert into a table in javascript with JsFiddle. (Afterwards, i want to use every single pair of coordinates in order to create one another feature and to export also a json file with coordinates and this feature but this is not my problem right now :P ). I enclosed this json file.. Thank you have a nice day! :)
My json file:
{
"displayFieldName": "",
"fieldAliases": {
"FID": "FID",
"Id": "Id",
"Longtitude": "Longtitude",
"Latitude": "Latitude"
},
"geometryType": "esriGeometryPoint",
"spatialReference": {
"wkid": 4326,
"latestWkid": 4326
},
"fields": [{
"name": "FID",
"type": "esriFieldTypeOID",
"alias": "FID"
}, {
"name": "Id",
"type": "esriFieldTypeInteger",
"alias": "Id"
}, {
"name": "Longtitude",
"type": "esriFieldTypeDouble",
"alias": "Longtitude"
}, {
"name": "Latitude",
"type": "esriFieldTypeDouble",
"alias": "Latitude"
}],
"features": [{
"attributes": {
"FID": 0,
"Id": 1,
"Longtitude": 23.739000000000001,
"Latitude": 37.972000000000001
},
"geometry": {
"x": 23.739000000000001,
"y": 37.972000000000001
}
}, {
"attributes": {
"FID": 1,
"Id": 2,
"Longtitude": 23.760100000000001,
"Latitude": 37.984999999999999
},
"geometry": {
"x": 23.760100000000001,
"y": 37.984999999999999
}
}, {
"attributes": {
"FID": 2,
"Id": 3,
"Longtitude": 23.749199999999998,
"Latitude": 37.975999999999999
},
"geometry": {
"x": 23.749199999999998,
"y": 37.975999999999999
}
}, {
"attributes": {
"FID": 3,
"Id": 4,
"Longtitude": 23.735700000000001,
"Latitude": 37.975999999999999
},
"geometry": {
"x": 23.735700000000001,
"y": 37.975999999999999
}
}]
}
You have to parse your file.
var fileContent = readTextFile("file:///C:/your/path/to/file.txt");
fielContent = JSON.parse(fileContent);
after this you can do with your json what you want, e.g take each coordinates
fileContent.features.each(function(point) {
console.log(point.geometry.x + " " + point.geometry.y);
});
Make sure that you modify for your needs.
You could try this.
To load your JSON:
function loadJSON(file,callback) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType('application/json');
xobj.open('GET', file, true);
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 && xobj.status == '200') {
// Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode
callback(xobj.responseText);
}
};
xobj.send(null);
}
To search through it and get whatever you want:
//return an array of objects according to key, value, or key and value matching
function getObjects(obj, key, val) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == 'object') {
objects = objects.concat(getObjects(obj[i], key, val));
} else
//if key matches and value matches or if key matches and value is not passed (eliminating the case where key matches but passed value does not)
if (i == key && obj[i] == val || i == key && val == '') { //
objects.push(obj);
} else if (obj[i] == val && key == ''){
//only add if the object is not already in the array
if (objects.lastIndexOf(obj) == -1){
objects.push(obj);
}
}
}
return objects;
}
//return an array of values that match on a certain key
function getValues(obj, key) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == 'object') {
objects = objects.concat(getValues(obj[i], key));
} else if (i == key) {
objects.push(obj[i]);
}
}
return objects;
}
//return an array of keys that match on a certain value
function getKeys(obj, val) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == 'object') {
objects = objects.concat(getKeys(obj[i], val));
} else if (obj[i] == val) {
objects.push(i);
}
}
return objects;
}
Example:
loadJSON('index.json', function(text){
var data = JSON.parse(text);
console.log(data);
var files = getObjects(data, 'type', 'file');
var fileNames = getValues(files, 'name');
var directories = getObjects(data, 'type','directory');
var directoryNames = getValues(directories, 'name');
});
Please try this
.json file
[
{
"Dzień": 1,
"Dyżur nocny": "Błotna 3",
"Dyżur świąteczny": "Wojska Polskiego "
},
{
"Dzień": 2,
"Dyżur nocny": "Zachlapana 9",
"Dyżur świąteczny": ""
}
]
.js file
(async function() {
const url = "s21.json";
const data = await (await fetch(url)).json();
console.log(data[1]);
})();
I am having below object where I am trying to get all the id values.
[{
"type": "test",
"id": "100",
"values": {
"name": "Alpha"
},
"validations": []
}, {
"type": "services",
"validations": [{
"id": "200",
"name": "John",
"selection": [{
"id": "300",
"values": {
"name": "Blob"
}
}]
}]
}]
Using the below code, I am getting only the first id value. Is there any way to get all the id values from the nested object without using any external module.
for (var prop in obj) {
console.log(prop)
if (prop === key) {
set.push(prop);
}
}
Expected Output
[100,200,300] //all id values
You can use a JavaScript function like below to get the nested properties:
function findProp(obj, key, out) {
var i,
proto = Object.prototype,
ts = proto.toString,
hasOwn = proto.hasOwnProperty.bind(obj);
if ('[object Array]' !== ts.call(out)) out = [];
for (i in obj) {
if (hasOwn(i)) {
if (i === key) {
out.push(obj[i]);
} else if ('[object Array]' === ts.call(obj[i]) || '[object Object]' === ts.call(obj[i])) {
findProp(obj[i], key, out);
}
}
}
return out;
}
Check this Fiddle for a working solution.
Using Object.keys
function findProp(obj, prop) {
var result = [];
function recursivelyFindProp(o, keyToBeFound) {
Object.keys(o).forEach(function (key) {
if (typeof o[key] === 'object') {
recursivelyFindProp(o[key], keyToBeFound);
} else {
if (key === keyToBeFound) result.push(o[key]);
}
});
}
recursivelyFindProp(obj, prop);
return result;
}
// Testing:
var arr = [{
"type": "test",
"id": "100",
"values": {
"name": "Alpha"
},
"validations": []
}, {
"type": "services",
"validations": [{
"id": "200",
"name": "John",
"selection": [{
"id": "300",
"values": {
"name": "Blob"
}
}]
}]
}];
console.log(findProp(arr, "id"));
To get the keys from nested objects, you first need to put your code in a function, then for each of the top-level keys, check if it's an array or object. If it is, just call your function again from within that function (weird, I know.) Just make sure you don't skip the check of whether it's an object. You'll get stuck in an infinite loop. Something like this:
function parseObjectKeys(obj) {
for (var prop in obj) {
console.log(prop)
var sub = obj[prop]
if (typeof(sub) == "object") {
parseObjectKeys(sub);
}
}
}
Here's a more complex example:
https://jsfiddle.net/tfqLnzLm/1/
You can use a XPath styled json parser like JSONPath. The version I'm presenting here is a extended version I did here:
function jsonPath(obj,expr,arg){var P={resultType:arg&&arg.resultType||"VALUE",result:[],normalize:function(e){var t=[];return e.replace(/[\['](\??\(.*?\))[\]']/g,function(e,r){return"[#"+(t.push(r)-1)+"]"}).replace(/'?\.'?|\['?/g,";").replace(/;;;|;;/g,";..;").replace(/;$|'?\]|'$/g,"").replace(/#([0-9]+)/g,function(e,r){return t[r]})},asPath:function(e){for(var t=e.split(";"),r="$",a=1,n=t.length;n>a;a++)r+=/^[0-9*]+$/.test(t[a])?"["+t[a]+"]":"['"+t[a]+"']";return r},store:function(e,t){return e&&(P.result[P.result.length]="PATH"==P.resultType?P.asPath(e):t),!!e},trace:function(e,t,r){if(e){var a=e.split(";"),n=a.shift();if(a=a.join(";"),t&&t.hasOwnProperty(n))P.trace(a,t[n],r+";"+n);else if("*"===n)P.walk(n,a,t,r,function(e,t,r,a,n){P.trace(e+";"+r,a,n)});else if(".."===n)P.trace(a,t,r),P.walk(n,a,t,r,function(e,t,r,a,n){"object"==typeof a[e]&&P.trace("..;"+r,a[e],n+";"+e)});else if(/,/.test(n))for(var l=n.split(/'?,'?/),s=0,c=l.length;c>s;s++)P.trace(l[s]+";"+a,t,r);else/^\(.*?\)$/.test(n)?P.trace(P.eval(n,t,r.substr(r.lastIndexOf(";")+1))+";"+a,t,r):/^\?\(.*?\)$/.test(n)?P.walk(n,a,t,r,function(e,t,r,a,n){P.eval(t.replace(/^\?\((.*?)\)$/,"$1"),a[e],e)&&P.trace(e+";"+r,a,n)}):/^(-?[0-9]*):(-?[0-9]*):?([0-9]*)$/.test(n)&&P.slice(n,a,t,r)}else P.store(r,t)},walk:function(e,t,r,a,n){if(r instanceof Array)for(var l=0,s=r.length;s>l;l++)l in r&&n(l,e,t,r,a);else if("object"==typeof r)for(var c in r)r.hasOwnProperty(c)&&n(c,e,t,r,a)},slice:function(e,t,r,a){if(r instanceof Array){var n=r.length,l=0,s=n,c=1;e.replace(/^(-?[0-9]*):(-?[0-9]*):?(-?[0-9]*)$/g,function(e,t,r,a){l=parseInt(t||l),s=parseInt(r||s),c=parseInt(a||c)}),l=0>l?Math.max(0,l+n):Math.min(n,l),s=0>s?Math.max(0,s+n):Math.min(n,s);for(var o=l;s>o;o+=c)P.trace(o+";"+t,r,a)}},eval:function(x,_v,_vname){try{return $&&_v&&eval(x.replace(/#/g,"_v"))}catch(e){throw new SyntaxError("jsonPath: "+e.message+": "+x.replace(/#/g,"_v").replace(/\^/g,"_a"))}}},$=obj;return expr&&obj&&("VALUE"==P.resultType||"PATH"==P.resultType)?(P.trace(P.normalize(expr).replace(/^\$;/,""),obj,"$"),P.result.length?P.result:!1):void 0}
// some extensions I have added to JSONPath
var jsonPathStore = function(obj,path,values) {
var maps=jsonPath(obj, path,{resultType:"PATH"})
maps.map(function(item,index) {
return eval( '(' + item.replace(/\$/,"obj") + '="' + values[index] +'"' + ')' );
})
}
var jsonPathDelete = function(obj,path) {
var maps=jsonPath(obj, path,{resultType:"PATH"})
maps.map(function(item,index) {
return eval( '(' + 'delete ' + item.replace(/\$/,"obj") + ')' );
})
}
var jsonPathRead = function(obj,path) {
var maps=jsonPath(obj, path,{resultType:"PATH"})
return maps.map(function(item,index) {
return eval( '(' + item.replace(/\$/,"obj") + ')' );
})
}
var jsonObject = [{
"type": "test",
"id": "100",
"values": {
"name": "Alpha"
},
"validations": []
}, {
"type": "services",
"validations": [{
"id": "200",
"name": "John",
"selection": [{
"id": "300",
"values": {
"name": "Blob"
}
}]
}]
}]
// this XPath will read all the id properties starting from the root element
console.log( "jsonPathRead All Ids" + JSON.stringify(jsonPathRead(jsonObject,"$..id"), null, 2) )
function getIds(obj) {
for (var x in obj) {
if (typeof obj[x] === 'object') {
getIds(obj[x]);
} else if (x === 'id') {
console.log(obj.id);
}
}
}
Below are my two arrays .I want to compare them and the resultant array should contain the updated values.Id's are common..
The arrays spans to n levels ie., there is no fixed levels..
The first array ie., the array before updation..
var parentArray1=[
{
"id": 1,
"name": "test",
"context": [
{
"id": 1.1,
"name": "test 1.1"
}
]
},
{
"id": 2,
"name": "test"
},
{
"id": 3,
"name": "test",
"context": [
{
"id": 3.1,
"name": "test 3.1"
}
]
},
{
"id": 4,
"name": "test"
}
]
The operations that i performed are
1.Adding a new Item
2.Updating an existing item
As a result of these two operations the changed values I will be getting in a different array..
ie.,
var changedArray=
[
{
"id": 1,
"name": "test1",
"context": [
{
"id": 1.1,
"name": "Changed test 1.1"
}
]
},
{
"id": 5,
"name": "test5"
}
]
Now I have written a generic function that loops through the parentArray1 and using the unique propertiesI need to either add a new item,if the item is there in the changedArray or update an existing item at any level
The resultant array should be ..
[
{
"id": 1,
"name": "test",
"context": [
{
"id": 1.1,
"name": "Changed test 1.1"
}
]
},
{
"id": 2,
"name": "test"
},
{
"id": 3,
"name": "test",
"context": [
{
"id": 3.1,
"name": "test 3.1"
}
]
},
{
"id": 4,
"name": "test"
},
{
"id": 5,
"name": "test5"
}
]
Generic function:
compareArray(parentArray1, changedArray, ["id"]);
function compareArray(array1, array2, propertyArray) {
var newItem = new Array();
array2.map(function(a1Item) {
array1.map(function(a2Item) {
/ If array loop again /
if (a2Item.constructor === Array) {
compareArray(a2Item, a1Item)
} else {
/ loop the property name to validate /
propertyArray.map(function(property) {
if (a2Item[property]) {
if (a2Item[property] === a1Item[property]) {
a2Item = a1Item
} else {
var isAvailable = _.find(newItem, function(item) {
return item[property] === a1Item[property]
})
if (!isAvailable) {
newItem.push(a1Item);
}
}
}
})
}
});
});
/ Insert the new item into the source array /
newItem.map(function(item) {
array1.push(item);
});
console.log("After Compare : " + array1);
}
I suggest to use a temporary object for the reference to the id and update if exist or push if not exist.
var parentArray1 = [{ "id": 1, "name": "test", "context": [{ "id": 1.1, "name": "test 1.1" }] }, { "id": 2, "name": "test" }, { "id": 3, "name": "test", "context": [{ "id": 3.1, "name": "test 3.1" }] }, { "id": 4, "name": "test" }],
changedArray = [{ "id": 1, "name": "test1", "context": [{ "id": 1.1, "name": "Changed test 1.1" }] }, { "id": 5, "name": "test5" }];
function insert(array, data) {
function iter(array) {
array.forEach(function (a) {
if (!('id' in a)) {
return;
}
if (o[a.id] !== a) {
o[a.id] = a;
}
Object.keys(a).forEach(function (k) {
Array.isArray(a[k]) && iter(a[k]);
});
});
}
var o = {};
iter(array);
data.forEach(function (a) {
if (o[a.id]) {
Object.keys(a).forEach(function (k) {
o[a.id][k] = a[k];
});
return;
}
array.push(a);
});
}
insert(parentArray1, changedArray);
document.write('<pre>' + JSON.stringify(parentArray1, 0, 4) + '</pre>');
This is what I came up with:
function sameKeys(o1, o2, keys) {
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (!o1.hasOwnProperty(key) || !o2.hasOwnProperty(key))
throw 'compared objects do not have the key ' + key;
if (o1[key] !== o2[key])
return false;
}
return true;
}
function isNothing(o) {
return typeof(o) === 'undefined' || o === null;
}
// this does not work if objects have functions as properties
function clone(o) {
if (isNothing(o))
return o;
return JSON.parse(JSON.stringify(o));
}
function extend(o1, o2, keys) {
if (isNothing(o2))
return;
if (isNothing(o1))
throw ('first parameter cannot be empty');
if (typeof(o1) != 'object' || typeof(o2) != 'object')
throw ('extend only works on objects');
Object.keys(o2).forEach(function (key) {
var newVal = o2[key];
if (o1.hasOwnProperty(key)) {
if (isNothing(newVal)) {
delete o1[key];
} else
if (Array.isArray(newVal)) {
compareArray(o1[key], newVal, keys);
} else {
switch (typeof(newVal)) {
case 'object':
extend(o1[key], newVal, keys);
break;
case 'boolean':
case 'number':
case 'string':
o1[key] = newVal;
break;
default:
throw 'not supported property type: ' + typeof(newVal);
}
}
} else {
o1[key] = clone(newVal);
}
});
}
function removeFromArray(arr, ids, keyArray) {
var indexes = [];
var it1s = arr.forEach(function (it, idx) {
if (sameKeys(ids, it, keyArray)) {
indexes.push(idx);
} else {
Object.keys(it).forEach(function (key) {
var newVal = it[key];
if (Array.isArray(newVal)) {
removeFromArray(it[key], ids, keyArray);
}
});
}
});
if (indexes.length) {
if (indexes.length > 1)
throw 'found multiple possible objects for the same key combination'
arr.splice(indexes[0], 1);
}
}
function compareArray(a1, a2, keyArray) {
a2.forEach(function (it2) {
var it1s = a1.filter(function (it) {
return sameKeys(it2, it, keyArray);
});
var it1;
if (!it1s.length) {
it1 = clone(it2);
a1.push(it1);
} else {
if (it1s.length > 1)
throw 'found multiple possible objects for the same key combination'
it1 = it1s[0];
extend(it1, it2, keyArray);
}
if (it2.removedIds) {
it2.removedIds.forEach(function (ids) {
removeFromArray(a1, ids, keyArray);
});
}
});
}
Use it with compareArray(parentArray1,changedArray,['id']);
Note that it would not work with objects that contain functions. Also, if the arrays would be large, perhaps a better solution is to sort both arrays by key, then always look from the last found object up. That's all I got for now.
Updated it with some concepts from Nina and some clearing of the code.
As I understood it, you only want to add properties. So extend({a: {b: 2}},{a:{c:3}}) will result in {a: {b:2,c:3}}. If this is not what you wanted, let me know.
I also added functionality for removing ids. If any of the objects in the array contains a removedIds array of the form [{id: 4},{id: 5}] then the items with those ids will be removed from the original array.
Slight modification on code, to satisfy your conditions. Try it!
function compareArray(originalArray, destinationArray, propertyArray) {
var newItem = new Array(), processedItem = new Array();
for (var i = 0; i < originalArray.length; i++) {
var sourceElement = originalArray[i];
for (var j = 0; j < destinationArray.length; j++) {
var destinationElement = destinationArray[j];
var isUpdated = false;
if (sourceElement.constructor === Array) {
compareArray(sourceElement, destinationElement, propertyArray);
} else {
/* loop the property name to validate */
propertyArray.map(function(property) {
if (sourceElement[property]) {
if (sourceElement[property] === destinationElement[property]) {
originalArray[i] = _.clone(destinationElement);
isUpdated = true;
return;
} else {
var isAvailable = _.find(newItem, function(item) {
return item[property] === destinationElement[property];
});
if (!isAvailable) {
var isAlreadyProcessed = _.find(processedItem, function(item) {
return item[property] === destinationElement[property];
});
if(!isAlreadyProcessed){
newItem.push(destinationElement);
}
}
}
}
});
}
if (isUpdated === true) {
break;
}
}
processedItem.push(sourceElement);
}
newItem.map(function(item) {
originalArray.push(item);
});
return originalArray;
}
I was trying to implement a search in a nested object.
// Returns an array of matching objects
function getObjects(obj, key, val) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == 'object') {
objects = objects.concat(getObjects(obj[i], key, val));
} else if (!$.isNumeric(obj[key]) && i == key && obj[key].toLowerCase().match(val)) {
objects.push(obj);
}
}
return objects;
}
This function returns the matching object on basis of key value pair provided.
What I want is the path to the object where key value pair is found.
Sample data
TestObj = {
"Categories": [{
"Product1": [{
"id": "a01",
"name": "Pine",
"description": "Short description of pine."
}, {
"id": "a02",
"name": "Pine",
"description": "Short description of pine."
}, {
"id": "a03",
"name": "Poplar",
"description": "Short description of poplar."
}],
"id": "A",
"title": "Cheap",
"description": "Short description of category A."
}, {
"Product2": [{
"id": "b01",
"name": "Maple",
"description": "Short description of maple."
}, {
"id": "b02",
"name": "Oak",
"description": "Short description of oak."
}, {
"id": "b03",
"name": "Bamboo",
"description": "Short description of bamboo."
}]
}]
};
I was trying to write a function
function objPath(obj, key, val, path) {
var result = [];
var passName = '';
if (path) {
passName = path;
}
var tempArray = [];
for (var prop in obj) {
var value = obj[prop];
if (typeof value === 'object') {
tempArray = objPath(value, key, val, passName);
$.each(tempArray, function (k, value) {
result.push(value);
});
} else if (prop == key && obj[key].toLowerCase().match(val)) {
result.push(obj[key]);
}
}
return result;
}
If I call function as
objPath(TestObj, 'id', 'b03');
Which should return Categories > Product2 > 3rd Row
But all I'm getting is the key. How to fix the objPath function to obtain required result
I have wrote a custom function
function objPath(obj, key, val, path) {
var result = [];
var passName = '';
if (path) {
passName = path;
}
var tempArray = [];
for (var prop in obj) {
var value = obj[prop];
if (typeof value === 'object') {
tempArray = objPath(value, key, val, passName);
$.each(tempArray, function (k, value) {
result.push(value);
});
} else if (!$.isNumeric(obj[key]) && prop == key && obj[key].toLowerCase().match(val)) {
result.push(passName + '["' + obj[prop] + '"]');
} else {
if ($.isNumeric(obj[prop])) {
//passName += ' > ' + obj[prop];
} else {
passName += '["' + obj[prop] + '"]';
}
}
}
return result;
}
Which will return
["Categories"]["Product2"]["b03"]