Category: How do I do X?
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

How Do I Use Smart JSON Substitution On Appsmith?

Issue

As an Appsmith user, I am having trouble with type casting in my code snippets. While one snippet works, another one doesn't. I am curious about what smart JSON substitution does and how I can use it in Appsmith.

Resolution

When working with APIs, queries, or JavaScript in Appsmith, you may notice that some code snippets behave differently even though they look similar. This often comes down to type casting and how Appsmith evaluates dynamic values inside JSON structures.

Smart JSON Substitution is an Appsmith feature that helps automatically preserve data types (such as numbers, booleans, arrays, or objects) when you bind dynamic expressions using {{ }}.

This article explains what smart JSON substitution is, why it matters, and how to use it correctly.

What Is Smart JSON Substitution?

Smart JSON substitution allows Appsmith to evaluate JavaScript expressions inside JSON fields and inject the result using its original data type, instead of converting everything into strings.

Without smart substitution, values like numbers or arrays may be treated as strings, which can cause API errors or unexpected behavior.

Why This Matters: A Common Example

❌ Without Smart JSON Substitution (String Casting)

{
  "userId": "{{ Input1.text }}"
}

If Input1.text contains 123, the API may receive:

{
  "userId": "123"
}

This is a string, not a number.

✅ With Smart JSON Substitution (Type Preserved)

{
  "userId": {{ Input1.text }}
}

If Input1.text contains 123, the API receives:

{
  "userId": 123
}

This preserves the number type.

How Smart JSON Substitution Works

Smart JSON substitution is applied when:

  • You are inside a JSON body (API body, query config, etc.)
  • You insert a JavaScript expression using {{ }}
  • The expression is not wrapped in quotes

Appsmith evaluates the expression and injects the result directly into the JSON.

Where to Find the Setting

Smart JSON Substitution is configured per query.

To locate it:

  1. Open your application in Edit mode.
  2. Select the API or database query.
  3. Click the Settings tab of the query.
  4. Look for the toggle labeled Smart JSON Substitution.

This toggle determines how Appsmith evaluates dynamic bindings for that specific query.