SOLVED

Need help with parsing json-string

Go to solution
milanjain2208
Level 2

Need help with parsing json-string

I have stored a json-string in a lead field in marketo =>

milanjain2208_0-1714936726702.png

 

{
  "name": "Milan",
  "cm_name": "Master Manager",
  "signature": "Hello \"There\"",
}

 

When I am trying to parse the json string using the following script =>

#if( $lead.emailVariables.isEmpty() )
#set( $lead.emailVariables = '{}' )
#end
#set( $emailVariables = '#set( $emailVariables = ' + $lead.emailVariables + ' )' )
#evaluate( $emailVariables )

milanjain2208_2-1714937010237.png


I am getting this error ->

Cannot get email content- <div>An error occurred when procesing the email Body! </div> <p>Encountered "There" near</p> <div><pre >#end</pre><pre >#set( $emailVariables = '#set( $emailVariables = ' + $lead.emailVariables + ' )' )</pre><pre class="x-form-item-label">#evaluate( $emailVariables ) &lt;/span&gt; </pre><pre >&lt;div&gt;</pre><pre >Dear ${lead.vFIRST_NAME_1}</pre></div>

 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Need help with parsing json-string

Velocity only supports long-form JSON Unicode escapes. It doesn’t support shortcuts like \" or \n. For the double quotes you use \u0022.

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Need help with parsing json-string

Velocity only supports long-form JSON Unicode escapes. It doesn’t support shortcuts like \" or \n. For the double quotes you use \u0022.

milanjain2208
Level 2

Re: Need help with parsing json-string

Got it. Thanks for the help.

sg
Level 2
Level 2

Re: Need help with parsing json-string

hi

I have followed the same steps, but still no luck in parsing the JSON from my Custom Object.

My Custom Object field (Field Name: RData) has data like below

 

sg_1-1716314811047.png

 

 

[
  {
    "StuLast": "Abram",
    "StuFirst": "Easton",
    "Program": "UGD",
    "Subject": "MUSC",
    "Catalog": "10A",
    "Section": 90
  },
  {
    "StuLast": "StuLast2",
    "StuFirst": "StuFirst2",
    "Program": "UGD",
    "Subject": "Chemistry",
    "Catalog": "20B",
    "Section": 65
  }
]

 

 

When I tried the following code in the Token to parse, I am getting an empty string

 

#set($data = ${registrar_cList.get(0).rData})
#if($data.isEmpty())
#set($data='{}')
#end
#set($parsedJson = '#set($parsedJson='+ $data+')')
#evaluate($parsedJson)
$parsedJson['subject']

 

 

My Custom object has data like 

sg_0-1716314664750.png

[
  {
    "StuLast": "Abram",
    "StuFirst": "Easton",
    "Program": "UGD",
    "Subject": "MUSC",
    "Catalog": "10A",
    "Section": 90
  },
  {
    "StuLast": "StuLast2",
    "StuFirst": "StuFirst2",
    "Program": "UGD",
    "Subject": "Chemistry",
    "Catalog": "20B",
    "Section": 65
  }
]

 

When I tried the following code in the Token to parse, I am getting an empty string

#set($data = ${registrar_cList.get(0).rData})
#if($data.isEmpty())
#set($data='{}')
#end
#set($parsedJson = '#set($parsedJson='+ $data+')')
#evaluate($parsedJson)
$parsedJson['subject']

 

Note: I did upload the csv file into Marketo as  UTF-8 format when updating the Custom object.

 

My Goal is to display data from this Custom object field in an email.

Any help is appreciated.

 

thanks

-Sree

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Need help with parsing json-string

Responded in the other thread. Please don’t cross-post, thanks.