Create json blobs using expressions

I am using the HTTPRequest node to post to an endpoint. The body parameter needs a json value which I need to create using expressions. However, some fields in the value field’s json needs to be pulled in from the previous node.

The issue is in the “name” parameter of the body parameters. The json should look like below where given, family etc must be pulled from the node’s input params:
{{ [
{
“use”: “official”,
“family”: “n8nlast1”,
“given”: [
“f1”,
“l1”
]
},
{
“use”: “usual”,
“given”: [
“f1”
]
}
]
}}

The expression creation UI renders the resulting json properly but the node detail screen shows an error “bodyParametersUI.parameter[1].value has an expression!”.

{
“nodes”: [
{
“parameters”: {
“requestMethod”: “POST”,
“url”: “https://xxx.preview.canvasmedical.com/Patient”,
“options”: {
“fullResponse”: true
},
“bodyParametersUi”: {
“parameter”: [
{
“name”: “resourceType”,
“value”: “Patient”
},
{
“name”: “name”,
“value”: “={{ [\n {\n “use”: “official”,\n “family”: “{{$json[“lastName”]}}”,\n “given”: [\n “f1”,\n “l1”\n ]\n },\n {\n “use”: “usual”,\n “given”: [\n “f1”\n ]\n }\n ]\n}}”
},
{
“name”: “birthDate”,
“value”: “1980-11-13”
},
{
“name”: “active”,
“value”: “={{true}}”
},
{
“name”: “extension”,
“value”: “={{ [\n {\n “url”: “”,\n “valueCode”: “UNK”\n }\n ]\n}}”
}
]
},
“headerParametersUi”: {
“parameter”: [
{
“name”: “Authorization”,
“value”: “Bearer xxx”
}
]
}
},
“name”: “HTTP Request1”,
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 1,
“position”: [
720,
740
]
}
],
“connections”: {}
}

Share the output returned by the last node

Information on your n8n setup

  • cloud, test instance

Hi @sona welcome to the community :tada:

Can you please send you code as Preformatted text, so in between

type or paste code here

It’s the 6th button in the toolbar.

Hello @dickhoning,
The json should look like below where the values for “family” and “given” are extracted from the node’s input json.

{
   {
      [
         {
            "use":"official",
            "family":“n8nlast1”,
            "given":[
               “f1”,
               “l1”
            ]
         },
         {
            "use":"usual",
            "given":[
               “f1”
            ]
         }
      ]
   }
}

@sona perhaps the Merge function might be the solution to your challenge …

Hello,
Just to close the loop here, I ended up using a function node to create the JSON that I needed and passed that to the httprequest node
Thanks for the support!