Zephr User Guide

JSON Transformations

2 views 0

The following transformations are available for JSON feature rules:

  • No Transformation

    Allows access to the content being served by the CMS. No changes are made to the content.

  • Set String

    Allows you to enter a value to set the targeted objects to a string. This is applied to the target, as it is an object operation, and the target object is replaced with the configured string.

  • Set JSON

    Allows you to target an object and replace it with a valid JSON object. This is applied to the target, as it is an object operation, and the target object is replaced with the configured JSON entity.

  • Set Boolean

    Allows you to target an object and replace it with a boolean. This is applied to the target, as it is an object operation, and the target object is replaced with the configured boolean value.

  • Set Number

    Allows you to target an object and replace it with a number.

  • Truncate String

    Allows you to truncate a string by providing a target property name, and specifying the number of words at which you want to truncate.This is applied to a property of the target object.

  • Truncate Array

    Allows you to truncate a string by providing a target property name, and specifying the number of array values at which you want to truncate. This is applied to a property of the target object.

For further information on these decision nodes, see the Transformations topic.

Example Truncate Array Transformation

In the following example, we truncate the body property from the JSON content that we used in the Example JSON Feature topic.

To truncate the body property, complete the following steps:

  1. In the Rules Builder, select the Transformations segment title
  2. Drag the Truncate Array decision node to your rules canvas

    The Truncate Array dialog box displays.

  3. Enter body in the Target property name text box
  4. Enter 2 in the Enter the number of array values to truncate text box

    The completed dialog box is as illustrated below:

    Truncate Array Example

  5. Select the Save button to add the decision node to your rule
  6. Drag from the white circle under the Page View node to the black circle to the left of the Truncate Array decision node, as illustrated below:

    Example Rule - Truncate Array

  7. Select the down arrow beside the Save as New Version button
  8. Select Save as New Version & Publish

When an end user encounters this rule, the JSON returns only two data blocks from the original four defined in the JSON content, as shown below:

{
    "data": {
       "getContentByUrl": {
          "page": {
             "__typename": "Article",
             "title": "This Is A Test Article",
             "body": [
                {
                   "__typename": "DataBlock",
                   "type": "TEXT",
                   "data": "\"<p><span><span><span><span><span><span>Here is the first paragraph of content.</span></span></span></span></span></span></p>\\n\""
                },
                {
                   "__typename": "DataBlock",
                   "type": "TEXT",
                   "data": "\"<p><span><span><span><span><span><span>Here is paragraph number two.</span></span></span></span></span></span></p>\\n\""
                   }
                ]
             }
          }
       }
    }