Open repl-mike-roest opened 5 years ago
Well I've gotten something to work but it's pretty gross.
I had to munge my json keys to remove - and replace with _ it's not nice but at least it allows me to dive into a deeper object with my update lookup function:
const lookup = (...args) => {
const res = jp.query(data, `$.${args.join('.')}`);
if(Array.isArray(res) && res.length === 1) {
return res[0];
}
return res;
}
And I added a additional helper method to munge values if I need to use them as lookups into other keys:
const keyify = (val) => {
return val.replace(/-/g,'_');
}
this allows me to do something like this in my template
{{$.plan.swimlane} | lookup:config:swimlanes:__:service:component_1:application_name}
and I can chain multiple lookups together if I need to do multiple dives to get to a key. But it still seems really messy and would appreciate any suggestions if there is a nicer way to do this.
I'm trying to use your library to do some object transformations and I'm trying to figure out a way to implement the following
Given this data document I'm trying to apply this template (logically)
But I can't seem to figure out a way to filter the config.swimlanes object by a parent level key. Is this possible? i found a hacky way to access a top level element referenced by the parent key with a custom function like so.
and then referencing it in the template
but it doesn't seem to work with a sub key
It just renders the raw string in the second case Thanks