Hi,

(Copied form Slack channel)

I’m seeing some confusing behaviours with the Expression Language json path 
functions and ReplaceText for adding JSON into a file (1.11.3):
given input of (read into a FlowFile attribute named record_json via the 
EvaluateJsonPath processor):
{
  "person": {
    "addresses": [
      {"current": true, "postcode": "test"}
    ]
  },
  "metadata": {}
}
UpdateAttribute to set address_1 as 
${record_json:jsonPath('$.person.addresses[?(@.current)].address_1')} results 
in a value of []. yet I’d have expected an empty String (as the json path 
doesn’t exist) - doing the same but for postcode correctly returns a value of 
test
UpdateAttribute to try and update record_json with 
${record_json:jsonPathPut('$.metadata', 'a_key', 'a_value')} results in the 
following output:
{
  "person": {
    "addresses": [
      {"current": true, "postcode": "test"}
    ]
  },
  "metadata": {},
  "metadata": {"a_key": "a_value"}
}
i.e. there’s a duplicated metadata object, where I’d have expected the new 
key/value pair to be added to the existing object instead (but can’t use 
jsonPathAdd as that’s for arrays, not objects
Also, when I try to then ReplaceText to put the attribute back into the file 
content (for various reasons I need it as both file content and an attribute 
later in the Flow), the above example output seems to lose the additional 
metadata object and just the blank object remains, i.e. a ReplaceText processor 
with settings Search Value = (?s)$.*$, Replacement Value = ${record_json}, 
Replacement Strategy = Regex Replace, Evaluation Mode = Entire text and the 
above example output gives file content of:
{
  "person": {
    "addresses": [
      {"current": true, "postcode": "test"}
    ]
  },
  "metadata": {}
}



Cheers,

-- 
Chris Sampson

t: +44 7867 843675
e: chris.samp...@naimuri.com

Reply via email to