jsonpath icon indicating copy to clipboard operation
jsonpath copied to clipboard

jp.stringify returns [object Object] if expression.type is 'union'

Open thotanaresh opened this issue 6 years ago • 1 comments

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']

thotanaresh avatar Sep 24 '18 04:09 thotanaresh

if (component.expression.type == 'string_literal') { value = JSON.stringify(component.expression.value) } else { value = component.expression.value; }

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;
    }

wzhonggo avatar Dec 27 '23 12:12 wzhonggo