Search through more than a hundred articles on every aspect of User.com

Marcin Szczygieł
Written by Marcin Szczygieł

Store your JSON file as a user attribute

Use JSON field format to store data in a simple and accessible way


Introduction

JSON file format is a special data type for custom attributes. It lets you store valid JSON objects inside it and use it similar to the snippet tags. It allows you to turn data and store in appropriate attributes. They allow you to personalize the content of your automatic or mass messages, using information stored there. There is no limit for the file size and also there is no limit for the level of nesting.

Usage

As an example we have JSON object exactly like above:

{
   'provider': {
       'category': {
           'name': 'some value’
       }
   }


As a first step, go to the Settings > App settings > User data & events > User attributes and create a new user attribute. Fill your name and as a value type choose JSON file format. 

Update your user attribute with that file. You're ready to use it.

How to render value for the name key?

Like in snippet tags, you have to refer to the name object with proper snippet. If this attribute is stored as a user attribute:

receiver.attribute_name.provider.category.name

Remember to change "attribute_name" to your attribute name.

A more advanced example can look like this:

{
    "glossary": {
        "title": "example glossary",
		"tag": {
            "title": "S",
			"GlossList": {
                "GlossEntry": {
                    "ID": "SGML",
					"SortAs": "SGML",
					"SGML": "Standard Generalized Markup Language",
					"Acronym": "SGML",
					"Abbrev": "ISO 8879:1986",
					"Test": {
                        "para": "A meta-markup language, used to create markup languages.",
						"Vall": ["GML", "XML"]
                    },
					"Type": "markup"
                }
            }
        }
    }
}


To get a value of ID for GlossEntry, you should use snippet tag like:

receiver.attribute_name.glossary.tag.GlossList.GlossEntry.ID


Trouble shooting:

Not sure why values of your JSON field are not rendered correctly?

You can check if your file is a valid JSON here: https://jsonlint.com/

Your key name has space inside?

Even if your JSON object is valid, we can't process value of this attribute.

Did you provide a proper key names?

Snippet tag is case sensitive (big letter is different from small).

Categories:
Tags:
  • JSON