Last active
March 17, 2020 02:25
-
-
Save Jlaird/45ecac1946faa7dfb3a625cf7bf34905 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cols = { | |
id: "test", | |
data: | |
{ | |
columns: | |
[ | |
{ name: "Date of Birth", dataValue: "response[*].dob"}, | |
{ name: "Name", dataValue: "response[*].name"}, | |
{ name: "hair", dataValue: "response[*].hair"} | |
] | |
} | |
}; | |
const res = { | |
response:[ | |
{ dob: "555551", name: "bob", hair: "bro"}, | |
{ dob: "555552", name: "carl", hair: "gree"}, | |
{ dob: "555553", name: "reggie", hair: "yell"}, | |
{ dob: "555554", name: "joe", hair: "bla"}, | |
] | |
}; | |
cols.data.columns.map(col => { | |
console.log('col', col); | |
const arr = col.dataValue.split('['); | |
array = res[arr[0]] | |
array.map(person => { | |
console.log('person', person); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
`
<script type="text/javascript"> /* JSONPath 0.8.0 - XPath for JSON * * Copyright (c) 2007 Stefan Goessner (goessner.net) * Licensed under the MIT (MIT-LICENSE.txt) licence. */ 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){return "[#"+(subx.push($1)-1)+"]";}) .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; ivar $ = obj;if (expr && obj && (P.resultType == "VALUE" || P.resultType == "PATH")) {
P.trace(P.normalize(expr).replace(/^$;/,""), obj, "$");
return P.result.length ? P.result : false;
}
} `