Save variable to object type

In node-red, how to save a variable to an object structure, not a string. Such as a JSON object

Hi @limengsong

Can you give an example of what you mean?

as the picture shows:
There are two properties for the workCenterCode and workCenterName name.
I want to use an attribute instead, such as workcenter:{code:"xxx",name:"xxx"}
Save as an object instead of a string.
The front-end component selects the select component.

How are you generating that object today?

There are lots of ways to structure a message object however you want it. The Function node with some JavaScript, the Change node can do it.

I'm not going to list out all the different ways it can be done.

If you can show us how you are building that object today, we can show you how to modify it to get what you want.

    <div class="form-row">
        <label for="node-input-workcenterCode" data-i18n="" ><i class="icon-tag"></i> </label>
        <select type="text" id="node-input-workcenterCode" style="width:70%;">

        oneditprepare: function () {
            var node = this;
                url: `/api/workCenters`,
                dataType: 'json',
                type: 'GET',
                success: (data) => {
                    if ( && > 0) {
                        for (let v of {
                            if (v.code !== node.workcenterCode) {
                                    `<option value=${v.code}>${}</option>`);
                            } else {
                                    `<option value=${v.code} selected = "selected" >${}</option>`
                error: (data) => {



Oh, you are talking about node properties. I thought you were asking about message structure.

You can use oneditsave you set node properties to whatever structure you want.

The Change node, for example, does just that for the list of rules you set in the node. Have a look at its html.


        oneditsave: function () {

like this?