skip to Main Content

Looking forward to an approach to convert simple JSON objects to Key value pair JSON objects using Logic Apps.
Like:

{
            "FirstName": "ABC",
            "LastName": "123",
            "MiddleName": null,
}

to

  [
    {
        "Key": "FirstName"
        "Value": "ABC"
    },
    {
        "Key": "LastName"
        "Value": "123"
    }
 ]

Thanks for the suggestions.

2

Answers


  1. I have followed the below steps to convert JSON Object to Key-Value pair JSON Objects-

    1. Created one "When a HTTP request is received" as below

    enter image description here

    1. Add a Parse Json action.
      I have taken triggerBody() in the Content field

    enter image description here

    Here Schema is

    {
    "properties": {
    "FirstName": {
    "type": "string"
    },
    "LastName": {
    "type": "string"
    },
    "MiddleName": {
    "type": "string"
    }
    },
    "type": "object"
    }
    
    1. After the Parse JSON action, add a Compose action.
      Enter the following expression in the Inputs field of the Compose action

       [
       {
               "Key": "FirstName",
               "Value": "@{body('Parse_JSON')['FirstName']}"
       },
       {
               "Key": "LastName",
               "Value": "@{body('Parse_JSON')['LastName']}"
       },
       {
               "Key": "MiddleName",
               "Value": "@{body('Parse_JSON')['MiddleName']}"
       }
       ]
      

    enter image description here

    1. Save and Run the logic app.

    Output

    enter image description here

    enter image description here

    Check in the Runs History

    enter image description here

    enter image description here

    Login or Signup to reply.
  2. As per my comment, you should (could) look at using the Advanced Data Operations connector, it has an operation which is specifically designed to complete your requirement.

    https://learn.microsoft.com/en-us/connectors/advanceddataoperatio/

    https://www.statesolutions.com.au/json-properties-to-name-value-pair-array/

    Flow

    This is the resulting JSON it will give back …

    [
      {
        "propertyName": "FirstName",
        "propertyType": "String",
        "propertyValue": "ABC"
      },
      {
        "propertyName": "LastName",
        "propertyType": "String",
        "propertyValue": "123"
      },
      {
        "propertyName": "MiddleName",
        "propertyType": "Null",
        "propertyValue": null
      }
    ]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search