jsonpath
jsonpath copied to clipboard
jp.stringify returns [object Object] if expression.type is 'union'
Consider paths object as
let paths= [{
"expression": {
"type": "identifier",
"value": "parentKey"
},
"scope": "child",
"operation": "member"
}, {
"expression": {
"type": "union",
"value": [{
"expression": {
"type": "string_literal",
"value": "key1"
}
}, {
"expression": {
"type": "string_literal",
"value": "key2"
}
}]
},
"scope": "child",
"operation": "subscript"
}];
console.log(jp.stringfy(paths));
This returns $.parentKey[[object Object],[object Object]]
But expected $.parentKey['key1','key2']
change to
if (component.expression.type == 'string_literal') {
value = JSON.stringify(component.expression.value)
}else if (component.expression.type == 'union') {
value = component.expression.value.map(function (item){
return item.expression.value;
}).join(",");
} else {
value = component.expression.value;
}