1
votes

I have a message.payload like:

...
    "data": {
        "itemType": 177,
        "fields": {
           "initial_conditions$177": "<p>Sample data</p>",
            "input_signals$177": "<p>Sample data</p>",
            "intermediate_signals$177": "<p>Sample data</p>",
            "output_signals$177": "<p>Sample data</p>",
            "hil_input_signals$177": "<p>Sample data</p>",
...

and the $177 is another field in payload (data.itemtype), but I can't figure out how to build this:

{
    "customfield_12507": message.payload.data.hil_use_case$177,
    "customfield_12508": message.payload.data.initial_conditions$177,
    "customfield_12509": message.payload.data.input_signals$177,
    "customfield_12510": message.payload.data.intermediate_signals$177,
    "customfield_12511": message.payload.data.output_signals$177,
    "customfield_12512": message.payload.data.hil_input_signal$177s,
}

Any pointers are welcome!

1

1 Answers

0
votes

I'm not positive I'm following and might need a complete payload and sample output, but is this what you're trying to do?

Input:

{
    "data": {
        "itemType": 177,
        "fields": {
        "initial_conditions$177": "<p>Sample data - changed to make more obvious</p>",
            "input_signals$177": "<p>Sample data</p>",
            "intermediate_signals$177": "<p>Sample data</p>",
            "output_signals$177": "<p>Sample data</p>",
            "hil_input_signals$177": "<p>Sample data</p>"
        }
    }
}

Data-weave (only did one field)

%dw 2.0
output application/json
---
{
    "customfield_12508": payload.data.fields["initial_conditions\$$(payload.data.itemType)"]
}

Which outputs

{
  "customfield_12508": "<p>Sample data - changed to make more obvious</p>"
}