Skip to content

Extract element from JSON object or valid JSON string by path. (Custom Variable Template for Google Tag Manager)

License

Notifications You must be signed in to change notification settings

mbaersch/extract-json-web

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Extract From JSON (Web GTM)

Custom Variable Template for Google Tag Manager

Extract element from JSON object or valid JSON string by path using dot-notation

Template Status Repo Size License


Usage

Create a new variable with this template. Choose a variable as input that holds an array or JSON object like a cookie value that contains consent settings. Then define a path to the desired element / property using dot-notation.

The variable will parse the input (if neccessary) and query the defined path. returns the value of the element. If the result is an object, if can be stringified.

Example

If the input consists of the following object or the corresponding JSON string:

{
  something: 42,
  some_object: {key1: 'value1', key2: 'value2', key3: 'value3'},
  items: [
    {itemName: 'example item 1', itemPrice: 199},
    {itemName: 'example item 2', itemPrice: 321.5},
  ]
}

... then the following paths will fetch these values:

Path Value
something 42
some_object.key3 value3
items[1].itemPrice 321.5
some_object {key1: 'value1', key2: 'value2', key3: 'value3'} (optionally as a string)

Querying an array with this template can be done by starting the path with an index. "[0]" as a path returns the first element; [0].price the "price" element in an object in the first element of an array.

About

Extract element from JSON object or valid JSON string by path. (Custom Variable Template for Google Tag Manager)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages