Jump to content

How to Replace element name with value in JSON


Obdurate -

Recommended Posts

TIBCO BW 5.14 I have below input records:

<Record>

<TESTID>1</TESTID>

<SCHEDULEDAY>2023-08-22</SCHEDULEDAY>

<CUSTID>5</CUSTID>

<MOBILENUMBER>222222222</MOBILENUMBER>

<RADIONUM>12345</RADIONUM>

</Record>

<Record>

<TESTID>2</TESTID>

<SCHEDULEDAY>2023-08-22</SCHEDULEDAY>

<CUSTID>5</CUSTID>

<MOBILENUMBER>222222222</MOBILENUMBER>

<RADIONUM>12345</RADIONUM>

</Record>

<Record>

<TESTID>3</TESTID>

<SCHEDULEDAY>2023-08-26</SCHEDULEDAY>

<CUSTID>6</CUSTID>

<MOBILENUMBER>222222222</MOBILENUMBER>

<RADIONUM>12345</RADIONUM>

</Record>

I want to use SCHEDULEDAY from above request and create JSON like this, where SCHEDULEDAY is used as element tag and both records of same SCHEDULEDAY are combined in jSON output.

Output JSON:

{

"finalData": {

"2023-08-22": [

{

"TESTID": 1,

"CUSTID": 5,

"Mobile": 1232434345,

"radioNum": 11

},

{

"TESTID": 3,

"CUSTID": 5,

"Mobile": 4545454524,

"radioNum": 22

}

],

"2023-08-26": [

{

"TESTID": 5,

"CUSTID": 6,

"Mobile": 4543466759,

"radioNum": 33

}

]

}

}

Link to comment
Share on other sites

  • 2 weeks later...

Hello @Obdurate -​ ,

I believe that natively, the replacement you want to perform is not possible. Complex elements are defined in the XSD schema, which is used to specify the structure of data to be used in your processes. It is not designed to have data elements with dynamic names or that can be substituted with other values at runtime. But, I ask that the experts correct me if I am mistaken.

However, since your message is not so extensive, there's nothing stopping you from building your own logic to meet this need.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...