0

i have a request like that;

{
    "i0": "4299",
    "l2": "1788",
    "c1": "3",
    "l4": "0",
    "t35": "V001*",
    "i4":"0",
    "l3":"0",
    "csubeno":"4299"
}

and i have a json file;

"ELJ": { "JTEXT1": { "value": "", "jsonPath": "$.parameters.request['c1']" }, "JNUM1": { "value": "", "jsonPath": "$.parameters.request['i0']"

i need to concat that two value --> c1 and i0 i tried something like that but it doest work.

"jsonPath": "$.parameters.request[c1,i0]"

Any suggestions?

i need to concatenate two value (c1 and i0)

Erhan
  • 13
  • 7
  • Does this answer your question? [How to concatenate JSON data into string?](https://stackoverflow.com/questions/25078340/how-to-concatenate-json-data-into-string) – Luuk Jul 15 '23 at 14:34
  • ty for answer. $.c1,i0 --> I think it can be used as an array like this, but I want to use it as text side by side. – Erhan Jul 15 '23 at 15:48
  • Why show 2 JSON files (a _request_, and a _json_ file ), and not tell what the relation between those two files is ? What is the expected output? (Or should we GUESS that your probably expect to get: `"34299"` ? (I do not like to GUESS .) – Luuk Jul 15 '23 at 16:38
  • :) i expected 3,4299 – Erhan Jul 15 '23 at 16:42

1 Answers1

0

When you have a JSON file (test.json) like:

{ "testA": "valueA", "testB": "valueB" }

you can do:

cat test.json | jq '."testA" + ."testB"'

to get the output: "valueAvalueB"

or you can do:

cat test.json | jq '"\(.testA)\(.testB)"'

to get the output: "valueAvalueB"

P.S. This was already answer here: https://stackoverflow.com/a/45527623/724039

P.P.S: jq is the tool that is available from GitHub here: https://jqlang.github.io/jq/

With your last edit, where output looks more like XML then JSON, you could do, (to get a JSON output!):

cat test.json | jq '{ "JTEXT1": (.testA + "," + .testB) }'

or

cat test.json | jq '{ "JTEXT1": "\(.testA),\(.testB)" }'

see: https://jqplay.org/s/ItQ06QjZDkW

Luuk
  • 12,245
  • 5
  • 22
  • 33