SOLVED

Re: Does Velocity Scripting Support JSON Field

Go to solution
Anonymous
Not applicable

Does Velocity Scripting Support JSON Field

Does velocity scripting for email support a json attribute. I am thinking of creating a custom object, called "Custom Event", then having a field in that custom event with a stingified json payload. Can I use velocity to serialize that string into json and then reference specific attributes of that object for the email tokens?

Thanks!

Related Threads:
Re: Velocity Scripts - Integrating Data From An External Database

1 ACCEPTED SOLUTION

Accepted Solutions
Kenny_Elkington
Marketo Employee

Re: Does Velocity Scripting Support JSON Field

I've seen similar things done just by using a text field, and then picking a delimiter and mapping each possible field to a particular array index.  So for example, you have these fields in your virtual object:

First Name

Last Name

Company

You would then serialize it with your selected delimiter like so:

Kenny|Elkington|Marketo

As long as you're serializing uniformly and always have the same indexes for fields, then you can get this:

#set($objectFieldArray = $myObjectList.get(0).split("|"))
#set($firstName = $objectFieldArray[0])

#set($lastName = $objectFieldArray[1])

#set($company = $objectFieldArray[2])

This will work for any type of flat record, but can be troublesome for objects with additional depth.

View solution in original post

8 REPLIES 8
Kenny_Elkington
Marketo Employee

Re: Does Velocity Scripting Support JSON Field

This isn't something that velocity is good at.​  What exactly is keeping you from just defining this in your object schema?

Anonymous
Not applicable

Re: Does Velocity Scripting Support JSON Field

The reason is because I am using a custom object as generic event, therefore there are many different types of attributes some which are different depending on the event type. The other option we were thinking was do a field with a delimiter of key and values. So the field would be:

Name - Attributes:

Value - DocumentUrl:http://www.test.com;DocumentName:TestDocument

Thanks!

Kenny_Elkington
Marketo Employee

Re: Does Velocity Scripting Support JSON Field

I've seen similar things done just by using a text field, and then picking a delimiter and mapping each possible field to a particular array index.  So for example, you have these fields in your virtual object:

First Name

Last Name

Company

You would then serialize it with your selected delimiter like so:

Kenny|Elkington|Marketo

As long as you're serializing uniformly and always have the same indexes for fields, then you can get this:

#set($objectFieldArray = $myObjectList.get(0).split("|"))
#set($firstName = $objectFieldArray[0])

#set($lastName = $objectFieldArray[1])

#set($company = $objectFieldArray[2])

This will work for any type of flat record, but can be troublesome for objects with additional depth.

Anonymous
Not applicable

Re: Does Velocity Scripting Support JSON Field

Thank you! In addition it would be nice if Marketo implemented a velocity plugin for serializing JSON such as https://github.com/lindenb/jsvelocity​ This would allow us to make events very generic and support a range of customization with minimal effort on marketo front. Imagine if we could access json + custom activities could be available in email scripting. We could do some amazing stuff

Kenny_Elkington
Marketo Employee

Re: Does Velocity Scripting Support JSON Field

Justin Cooperman​, this might be worth a look.

Anonymous
Not applicable

Re: Does Velocity Scripting Support JSON Field

See these feature requests:

Thanks,

Brad

Anonymous
Not applicable

Re: Does Velocity Scripting Support JSON Field

Kenny Elkington​ Since Velocity seems to support XML, have you seen people do this with XML instead of JSON. In addition do you happen to know when Marketo references

You can reference first and second level custom objects that are directly connected to the Lead or Contact, but not third-level custom objects.

Does this mean if a Lead has many Opportunities, and those opportunities have many Proposals... is Lead considered top level, and opportunities 2nd level? Would proposals be 3rd level?

Also what is the max length by default on a string on a custom obejct? Is this changeable by support?

Thanks!

Kenny_Elkington
Marketo Employee

Re: Does Velocity Scripting Support JSON Field

I have not seen anyone use XML for this with velocity, but we do not enable the XML tool in Marketo, so I think it would be a similarly tough scenario to JSON.

>Does this mean if a Lead has many Opportunities, and those opportunities have many Proposals... is Lead considered top level, and opportunities 2nd level? Would proposals be 3rd level?

You can't link to custom objects through opportunities in Marketo, so this isn't applicable here.

>Also what is the max length by default on a string on a custom obejct? Is this changeable by support?

Strings are 255, Text is 2000, and Text Area is 30000, none of the lengths are alterable.