InvalidJsonError in Object Assign when string have line break

Hi, i’m trying to use the node Object Assign, but the node is returning the error :

InvalidJsonError
template did not render to valid JSON.

I tried to use double quotes, triple brackets, jsonEncode, without double quotes, but nothing.

What I observed is that when my string “additional_description” doesn’t have line breaks, the workflow works.
In the figure below, my string have line break, causing error.

How can I solve that?

I got it to work by doing the following:

So, instead of "prop": "{{path.to.string.value}}", try "prop": {{jsonEncode path.to.string.value}}.

Hi Dylan,

I’ve already tried this before, but returns the same error.

I forgot to say that this value can be null, so may be working.machineOrder.additional_description (in my example) cannot be found.

I can do currentOrder: {{ jsonEncode working.machineOrder }} too, but again, this value can be null, that is the reason that i’m using double quotes.

So, how can I proceed?

To contextualize: the machineOrder values are coming from an array that is returned from Table: Get Rows node.

Im using the array node just to assign the first value from the array tableResult to working.machineOrder

I found a solution.
I removed the object node and used function node, my code:

payload.working.mappedMachine = {
    id: payload.working.mac.id,
    name: payload.working.mac.tags.machineName[0],
    lat: payload.working.mac.tags.inPlantLat[0],
    long: payload.working.mac.tags.inPlantLong[0],
    patrimony: payload.working.mac.tags.patrimony[0],
    condition: payload.working.mac.compositeState.condition.value,
    connectionInfo: {
        connected: payload.working.mac.connectionInfo.connected,
        time: payload.working.mac.connectionInfo.time
    },
    alarms: {
        totalHealthy: payload.working.mac.compositeState.totalSaudavel.value,
        totalWarning: payload.working.mac.compositeState.totalAlerta.value,
        totalCritical: payload.working.mac.compositeState.totalCritico.value
    },
    indicators: {
        om_c: payload.working.points?.om_c ?? "",
        hmp: payload.working.points?.hmp ?? "",
        tmef: payload.working.points?.tmef ?? "",
        tmpr: payload.working.points?.tmpr ?? "",
        te: payload.working.points?.te, ?? ""
        cost: payload.working.points?.cost ?? ""
    },
    currentOrder: {
        id: payload.working.machineOrder?.id ?? "",
        description: payload.working.machineOrder?.description ?? "",
        notifierName: payload.working.machineOrder?.notifier_name ?? "",
        notifierPhone: payload.working.machineOrder?.notifier_phone ?? "",
        conclusionDate: payload.working.machineOrder?.conclusion_date ?? "",
        additionalDescription: payload.working.machineOrder?.additional_description ?? "",
        employee: payload.working.machineOrder?.employee ?? ""
    }
}

This works, but idk if this is a good solution.

I’m still not seeing the problem you are describing, as {{jsonEncode path.to.null.value}} (unquoted) is still outputting the expected result for me. See attached.

Can you PM me the workflow export file and a sample payload?

For sure, just a second!