wanglingsong/JsonSurfer

Values nested in array not supported

splatch opened this issue · 4 comments

My use case is rather simple as I do not do any filtering but flattening of remote service response. My use case is supported by jq, but fails to get evaluated with JsonSurfer (and json path too).

My jq expression is
.entry[] | {url: .fullUrl, values: [ .resource.component[]? | .valueQuantity.value ] }

Which could be translated to json surfer:
$.entry['fullUrl', resource.component[*].valueQuantity.value]

However there are two major issues. From my evaluation it seems that ['property1', 'property2'] syntax always returns first property value and ommits second. Second issue is array wildcard path operator after which no more additional emenets may occur (althrought it passes compilation). Depending on expression variant it will cause class cast exception (usage of ['property'] syntax in context of array) or operation not supported exceptions ([*].property).

Are there any chances for support of such scenarios?

For reference I attach simplified resource model I have.

{
  "entry": [{
    "fullUrl": "http://localhost:8080/test/314",
    "resource": {
      "id": "56",
      "meta": {
        "lastUpdated": "2017-12-07T22:44:51.744+01:00"
      },
      "effectiveDateTime": "2009-09-09T00:00:00",
      "component": [{
        "valueQuantity": {
          "value": 109
        }
      },{
        "valueQuantity": {
          "value": 119
        }
      }]
    }
  },{
    "fullUrl": "http://localhost:8080/test/318",
    "resource": {
      "id": "57",
      "valueQuantity": {
        "value": 100
      }
    }
  }]
}

Output given by jq:

{
  "url": "http://localhost:8080/test/314",
  "values": [
    109,
    119
  ]
}
{
  "url": "http://localhost:8080/test/318",
  "values": []
}

(second resource does not have "component" embedded but valueQuantity directly at resource level)

Could you show what is the expected result from your expression?
Besides, I don't think it is a valid json using [] for object.

{
   "entry": [
      "fullUrl": "xyz",
      "resource": resource ...
  ]
}

You’re right I messed up first part, it should be object instead of array.

Hi, I've updated example with complete json structure and updated JQ expression which handles null values too.

um... maybe there is a misunderstanding. JsonSurfer can't do any transformation on provided json. It can only locate and extract value by provided JsonPath.