9 Replies Latest reply on Feb 25, 2019 11:12 AM by Mark Price

    JSON Parser

    Harish Gupta

      Hi,

       

      I am sending a Json file using Post request to Marketo. Here is the JSON:

       

      {

       

       

      "action":"createOrUpdate",

       

      "lookupField":"email",

       

      "input":[

       

       

      {

      "requestedCampaignType":"orderConfirmation",

      "totalProductPurchased":"2",

      "shippingAddress":"48 B",

      "shippingCity":"Jammu",

      "shippingState":"Jammu and Kashmir",

      "shippingCountry":"India",

       

       

      "sampleJson" : [

      {

        "ProductID" : "1",

        "ProductName" : "Mi Mix 2 (Black, 128 GB)",

        "ProductPrice" : "$ 299.98",

        "Quantity" : "1",

        "ProductColor":"Midnight Black"

      },

      {

        "ProductID" : "2",

        "ProductName" : "Mi Mix 3 (Black, 256 GB)",

        "ProductPrice" : "$ 399.98",

        "Quantity" : "1",

        "ProductColor":"Midnight Black"

      }

      ]

      }

      ]

      }

       

       

      The field "sampleJson" is a textarea type field. When i am checking this data in Marketo under "sampleJson" file, it's coming like:

       

      [{

      ProductID=1, ProductName=AC (Black, 128 GB), Product Price=$ 599.98, Quantity=1, ProductColor=Midnight Dark}, {ProductID=2, ProductName=Cooler (Black, 256 GB), Product Price=$ 399.98, Quantity=1, ProductColor=Dark Black

      }]

       

      Can anyone  help me with the reason why Marketo is changing the format of nested json and what is the correct way to keep the format similar in Marketo like I am sending in my post  request.

       

      Also, my Velocity script is successfully parsing the JSON when i am storing it like:

      [

      {

        "ProductID" : "1",

        "ProductName" : "Mi LED",

        "ProductPrice" : "$ 299.98",

        "Quantity" : "1",

        "ProductColor":"Dark Black"

      },

      {

        "ProductID" : "2",

        "ProductName" : "LG Cooler",

        "ProductPrice" : "$ 399.98",

        "Quantity" : "1",

        "ProductColor":"Dark Red"

      }

      ]

       

      but If I run my Velocity script on the format which Marketo is changing then Marketo is showing the error and script is not running.

       

      Please suggest.Sanford Whiteman

        • Re: JSON Parser
          Jim Thao

          Because the results you shared were so different from the post, I just want to ask, are you sure you're validating against the correct record in Marketo?

          • Re: JSON Parser
            Sanford Whiteman

            Echoing Jim, there's something wrong with your testing setup.

             

            Marketo doesn't change the contents of Textarea fields like that. They're opaque blocks of data.

             

            The unwanted data you've shown is exactly what you'd see in Velocity *after* successful parsing of a JSON-like string into an ArrayList of HashMaps (it's the Velocity serialization format).

            • Re: JSON Parser
              Mark Price

              Hi Harish,

               

              It seems like you have a JSON object as the value for "sampleJSON" in the API call.  Perhaps Marketo is formatting the data writing to the text area. 

               

              The last time I did this setup, I want to say I passed an escaped string as the field value in the API call:

               

              "sampleJSON" : "[{\"recommendation1\":{\"resultCount\":\"3\",\"product1url\":\"https://website.com/product-1\"}}]"

               

              hope you get it sorted!

              1 of 1 people found this helpful