How to make prompt(user messsage) from object

Describe the problem/error/question

how can i add some string, in Prompt in AI Agent node?

{{ $json.data }} is a [Array: [{name:”Lee Yi”, score:79"},{name:”Wong Yi”, score:99"}]

if i put some string +{{ $json.data }} it wont show the result.

Information on your n8n setup

  • n8n version: 1.108.0
  • Database (default: SQLite): SQLITE
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system:

Hi @KennethYCK welcome to the :n8n: community!

That happens because {{ $json.data }} is an array/object in your case, and you can’t concatenate strings with objects directly, You’ll need to convert it into a string first..

You can do this by wrapping it in JSON.stringify() (or .toJsonString()):

try this:

{{ JSON.stringify($json.data) }}

Hi Kenneth,

You’re very close. The issue is how n8n renders values inside Prompt fields.

  • Text you type is literal.

  • Anything inside {{ ... }} is one expression that must evaluate to a string.

  • If you insert an object/array directly, it will show as [object Object]. You need to stringify or format it.

So instead of:

some string +{{ $json.data }}

use one of these:

1) Quick and simple (stringify the whole array)

some string {{ JSON.stringify($json.data) }}

2) Nicely formatted list

Here are the results:
{{ $json.data.map(x => `${x.name} (score: ${x.score})`).join('\n') }}

3) Everything inside one expression (also fine)

{{ 'some string ' + JSON.stringify($json.data) }}

Tip: keep the + inside the {{ ... }} (or don’t use it at all — plain text + {{ expression }} works) and make sure your expression returns a string.

To build a prompt that mixes static text and data from a previous node you need to remember two things about n8n expressions:

  • Everything inside double‑curly braces ({{ … }}) is evaluated as JavaScript. Anything outside is sent as plain text.

  • Objects and arrays are not automatically formatted; if you insert an object directly you’ll see [Object object] or similar. To show data you must convert it to a string or iterate over it.

Here’s how you can achieve what you want:

  1. Convert the array to a JSON string – this is the simplest way to show the array contents. Use JSON.stringify() inside the expression:

    Here is the data: {{ JSON.stringify($json.data) }}
    
    

    The n8n docs note that some nodes expect stringified JSON rather than objects: community.n8n.io, and using JSON.stringify() solves this.

  2. Format the array nicely – if you only want specific fields (e.g. name and score), map over the array and join the results:

    Student scores:
    {{ $json.data.map(item => `${item.name}: ${item.score}`).join('\n') }}
    
    

    This expression produces a list like:

    Lee Yi: 79
    Wong Yi: 99
    
    
  3. Concatenate static text and dynamic data inside the expression – if you prefer to add a prefix on the same line, keep the concatenation inside the braces:

    {{ 'Scores ➜ ' + JSON.stringify($json.data) }}
    
    

    Placing the plus sign inside the braces ensures the expression is evaluated. Writing Some text + {{ $json.data }} outside of the braces will not work because only the part in {{ … }} is evaluated.

Using these patterns you can build complex prompts that include both static text and dynamic data from previous nodes.

1 Like

thanks, it works

Glad it work @KennethYCK, please mark my reply as the solution, thanks

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.