Conditional Data Icons

Overview

When creating Data Objects in our data model. We can choose various icons and colors for that object. You can create various sets of icons and determine which to render by using conditional logic defined in JSON logic.

This guide explains how to write JSONlogic expressions for dynamic icon display in the Cloneable Cloud Platform. Icon conditionals allow you to display different icons based on the values of data object fields, providing visual feedback about data status in real-time.

Table of Contents

Basic Concepts

How Icon Conditionals Work

When you create a data object template with multiple icons, the system:

  1. Evaluates conditionals in the order they appear

  2. Returns the first matching icon where the conditional evaluates to true

  3. Falls back to default icon if no conditionals match

  4. Uses the first icon as final fallback

Icon Configuration Structure

Default vs Conditional Icons

  • Default icons: No conditional or empty conditional ({} or "")

  • Conditional icons: Have a valid JSONlogic expression in the conditional field

JSONlogic Syntax

JSONlogic uses JSON objects to represent logical expressions. The basic structure is:

Basic Structure Examples

Field Value Access

Accessing Field Values

Use the var operator to access field values from your data object:

Important Notes About Field Values

  • String values: Simple values like "true", "false", numbers are kept as strings

  • JSON objects: Complex values starting with { or [ are parsed as JSON

  • Null handling: Use null (not "null") in conditionals for null checks

Example Field Value Processing

Common Operators

Comparison Operators

Logical Operators

Null and Existence Checks

Array and Object Operations

Practical Examples

Example 1: Simple Status-Based Icons

Example 2: Complex Multi-Condition Logic

Example 3: Data Quality Indicators

Utility Industry Use Cases

Pull Inspection Status

Pole Condition Assessment

Project Progress Tracking

Best Practices

1. Use Descriptive Icon Names

2. Order Icons by Specificity

Place more specific conditions first, general conditions last:

3. Handle Edge Cases

Troubleshooting

Common Issues

1. Conditional Always Returns False

Problem: Icon never appears even when condition should be true

Solutions:

  • Check field name spelling in {"var": "field_name"}

  • Verify field value format (string vs parsed JSON)

  • Add null check: {"!=": [{"var": "field_name"}, null]}

2. JSON Parse Error

Problem: Invalid JSON syntax in conditional

Solutions:

  • Use double quotes for all strings

  • Escape quotes in nested JSON: \"

  • Validate JSON with online tools

3. Wrong Icon Displayed

Problem: Unexpected icon appears

Solutions:

  • Check icon order (first match wins)

  • Add more specific conditions

  • Verify logical operators (and vs or)

4. No Icon Displayed

Problem: No icon appears at all

Solutions:

  • Ensure at least one icon has empty conditional ({})

  • Check icon encoding format

  • Verify icon array is not empty

Debug Examples

Validation Tools

Use these tools to validate your JSONlogic:

  1. JSON Validator: Ensure valid JSON syntax

  2. JSONlogic Playground: Test expressions online

  3. Browser Console: Test with real data

  4. Icon Customizer: Built-in validation in the platform

Advanced Examples

Complex Utility Workflows

Conclusion

JSONlogic provides powerful conditional logic for dynamic icon display in the Cloneable Cloud Platform. By following this guide, you can create sophisticated visual indicators that help utility workers quickly understand data status, quality, and progress at a glance.

Remember to:

  • Start with simple conditions and build complexity gradually

  • Test thoroughly with real data

  • Use meaningful colors and icons

  • Handle edge cases and null values

  • Order conditions from most specific to most general

For additional support, refer to the test examples in the codebase or consult the JSONlogic documentation at jsonlogic.com.

Last updated