How to convert JSON format to String format

Hi All,

I have requirement which i need to convert below mentioned JSON format to..

{
  "requestId": "221a0000-faff-00e3-ac11-dbe6ebd00d00",
  "sourceSystemName": "ABCD",
  "requestDateTime": "2023-08-23T15:03:31.919Z",
  "requestInitiator": "App Name",
  "context": "/fetchData",
  "data": {
    "kind": "fetchDataRequest",
    "items": [
      {
        "item": {
          "key": "ID",
          "value": [
            "1234567890"
          ]
        }
      },
      {
        "item": {
          "key": "CRITERIA",
          "value": [
            "EMPLOYEEDETAILS",
            "INCLUDEIDDETAILS"
          ]
        }
      }
    ]
  }
}

.. this string format:

"{
""requestId"": ""221a0000-faff-00e3-ac11-dbe6ebd00d00"",
""sourceSystemName"": ""ABCD"",
""requestDateTime"": ""2023-08-23T15:03:31.919Z"",
""requestInitiator"": ""App Name"",
""context"": ""/fetchData"",
""data"": {
""kind"": ""fetchDataRequest"",
""items"": [
{
""item"": {
""key"": ""ID"",
""value"": [
""1234567890""
]
}
},
{
""item"": {
""key"": ""CRITERIA"",
""value"": [
""EMPLOYEEDETAILS"",
""INCLUDEIDDETAILS""
]
}
}
]
}
}"

How to achieve this? After converting i need to pass in Request Body of integration to get data.

Regards,
Sandeep

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Senior Developer
    in reply to Sandeep

    Hi   could you try this code, This code converts json data to string

    touniformstring(
      a!fromJson(
      "
    {
    ""requestId"": ""221a0000-faff-00e3-ac11-dbe6ebd00d00"",
    ""sourceSystemName"": ""ABCD"",
    ""requestDateTime"": ""2023-08-23T15:03:31.919Z"",
    ""requestInitiator"": ""App Name"",
    ""context"": ""/fetchData"",
    ""data"": {
    ""kind"": ""fetchDataRequest"",
    ""items"": [
    {
    ""item"": {
    ""key"": ""ID"",
    ""value"": ""1234567890""
    }
    },
    {
    ""item"": {
    ""key"": ""CRITERIA"",
    ""value"": [""EMPLOYEEDETAILS"", ""INCLUDEIDDETAILS""]
    }
    }
    ]
    }
    }
    "
    ))
    

  • Yes Abhishek this will convert JSON to String, but i don't want to convert the format which i was expecting the format to be.

    If you see my query in starting of conversation, i need to convert below mentioned format to...Continuation...

    {
      "requestId": "221a0000-faff-00e3-ac11-dbe6ebd00d00",
      "sourceSystemName": "ABCD",
      "requestDateTime": "2023-08-23T15:03:31.919Z",
      "requestInitiator": "App Name",
      "context": "/fetchData",
      "data": {
        "kind": "fetchDataRequest",
        "items": [
          {
            "item": {
              "key": "ID",
              "value": [
                "1234567890"
              ]
            }
          },
          {
            "item": {
              "key": "CRITERIA",
              "value": [
                "EMPLOYEEDETAILS",
                "INCLUDEIDDETAILS"
              ]
            }
          }
        ]
      }
    }

    ...Continuation...this format (Expecting format):

    "{
    ""requestId"": ""221a0000-faff-00e3-ac11-dbe6ebd00d00"",
    ""sourceSystemName"": ""ABCD"",
    ""requestDateTime"": ""2023-08-23T15:03:31.919Z"",
    ""requestInitiator"": ""App Name"",
    ""context"": ""/fetchData"",
    ""data"": {
    ""kind"": ""fetchDataRequest"",
    ""items"": [
    {
    ""item"": {
    ""key"": ""ID"",
    ""value"": [
    ""1234567890""
    ]
    }
    },
    {
    ""item"": {
    ""key"": ""CRITERIA"",
    ""value"": [
    ""EMPLOYEEDETAILS"",
    ""INCLUDEIDDETAILS""
    ]
    }
    }
    ]
    }
    }"

    Regards,
    Sandeep

  • 0
    Certified Lead Developer
    in reply to Sandeep

    Could you share your full code please?

  • Hi David,

    Please refer to this code, this is same which i have shared in above conversation.
    I need to dynamically create below mentioned parameters values which are:
    1. Create UUID for requestId parameter.
    2. ID need to pass dynamically

    Later that this entire JSON code i need to convert as String in order to pass in Request body for getting Coverage data.

    {
      "requestId": "221a0000-faff-00e3-ac11-dbe6ebd00d00",
      "sourceSystemName": "ABCD",
      "requestDateTime": "2023-08-23T15:03:31.919Z",
      "requestInitiator": "App Name",
      "context": "/fetchData",
      "data": {
        "kind": "fetchDataRequest",
        "items": [
          {
            "item": {
              "key": "ID",
              "value": [
                "1234567890"
              ]
            }
          },
          {
            "item": {
              "key": "CRITERIA",
              "value": [
                "EMPLOYEEDETAILS",
                "INCLUDEIDDETAILS"
              ]
            }
          }
        ]
      }
    }

    Regards,
    Sandeep