if there is a Json java script variable on the page, how could I populate UDO with data in it, what is the syntax please?

Silver Contributor
Silver Contributor
 
4 REPLIES 4

if there is a Json java script variable on the page, how could I populate UDO with data in it, what is the syntax please?

Tealium Employee

The easiest way is probably to use the "Flatten JSON objects" extension to convert it into a standard javascript object. It's documented here: https://community.tealiumiq.com/t5/Tealium-iQ/Flatten-JSON-Objects-Extension/ta-p/13705

Connecting data systems since the 1980s.

if there is a Json java script variable on the page, how could I populate UDO with data in it, what is the syntax please?

Silver Contributor
Silver Contributor
Hi Steve thanks, but when this extension will be executed? and also I have to use this extension first and then another extension to set UDO value from the new varible, it is a bit too complicated? Can I use java script to do it, but just could not find documentation related here.

if there is a Json java script variable on the page, how could I populate UDO with data in it, what is the syntax please?

Tealium Employee
You can scope the extension(s) to a specific tag if you want, then they will be executed with the tag, or if you do just want to use javascript you could convert it with an eval command - (see http://www.w3schools.com/json/json_eval.asp ) and then just pick it up as a javascript variable.
Connecting data systems since the 1980s.

if there is a Json java script variable on the page, how could I populate UDO with data in it, what is the syntax please?

Employee Emeritus
Hey Gang, Perhaps something like this would work: function mergeObects(obj1,destObj){ for(var x in obj1){ destObj[x] = obj1[x]; } utag_data = destObj; } mergeObects(test,utag_data) Paste this into a JavaScript Code extension scoped to PreLoader. This is using a JSON object called "test" and looping through the all the attributes within that object and assigning them to the utag_data object The first argument of the 'mergeObjects' function is the JSON object that you want to pull the data from, and the second argument in the function is the object you would like to send the data to. This assumes the JSON objects do not have attributes with the same name. If they do the destination object will get overwritten. Hope this helps. Here is are a couple jQuery methods as well: http://api.jquery.com/jquery.merge/ http://api.jquery.com/jquery.extend/
Public