Quotes and escaping in transform expressions

#1

Is there documentation on the different cases such as

  • expression {id: “Manufacturer”}

  • expression “{“id”: “‘lumen’”}”

? (Note the single quotes around “lumen”.)

Thanks,
Alex

0 Likes

Help updating multiple Meta fields with a ternary?
Transform expression syntax
#2

I am actually waiting to see what compiles, I believe there are typos in the project text.

0 Likes

#3

Given this canonical object:

{
  unitId: "lumen"
}

And a transformation destination type with fields field[0-27] of type Unit

All of the following transformations marked with :+1: will produce the correct output (a reference to a Unit with id lumen):

field0: ~ expression {id: 'unitId'} // 👍
field1: ~ expression {id: "unitId"} // 👍

field2: ~ expression {'id': 'unitId'} // 👍
field3: ~ expression {"id": "unitId"} // 👍

field4: ~ expression '{id: "unitId"}' // 👍
field5: ~ expression "{id: 'unitId'}" // ⛔️ id becomes "unitId" (without quotes)

field6: ~ expression '{"id": "unitId"}' // 👍
field7: ~ expression "{'id': 'unitId'}" // ⛔️ transform error: null

field8: ~ expression '{id: \'unitId\'}' // ⛔️ id becomes "unitId" (without quotes)
field9: ~ expression "{id: \"unitId\"}" // 👍
field10: ~ expression '{"id": \'unitId\'}' // ⛔️ id becomes "unitId" (without quotes)
field11: ~ expression "{'id': \"unitId\"}" // ⛔️ transform error: null
field12: ~ expression '{\'id\': \'unitId\'}' // ⛔️ transform error: null
field13: ~ expression "{\"id\": \"unitId\"}" // 👍

field14: ~ expression {id: "'lumen'"} // 👍
field15: ~ expression {id: '"lumen"'} // ⛔️ Error Msg: Invalid expression "\"lumen\"": illegal character
field16: ~ expression {id: '\"lumen\"'} // ⛔️ Error Msg: Invalid expression "\"lumen\"": illegal character

field17: ~ expression "{id: 'lumen'}" // 👍
field18: ~ expression '{id: \'lumen\'}' // 👍
field19: ~ expression '{id: "\'lumen\'"}' // 👍
field20: ~ expression "{id: \"'lumen'\"}" // 👍

field21: ~ expression "{\"id\": 'lumen'}" // 👍
field22: ~ expression '{"id": \'lumen\'}' // 👍
field23: ~ expression '{"id": "\'lumen\'"}' // 👍
field24: ~ expression "{\"id\": \"'lumen'\"}" // 👍

field25: ~ expression "{id: '\"lumen\"'}" // ⛔️ id becomes "lumen" (with quotes)
field26: ~ expression '{id: \'"lumen"\'}' // ⛔️ id becomes "lumen" (with quotes)
field27: ~ expression {id: unitId} // ⛔️ provisioning error: Invalid value '{}' for JSON object.

Obviously, some transform expressions are cleaner than others. IMO, the easiest to read are options 0, 1, and 14.

8 Likes

Normalize on PhysicalMeasurementSeries
#4

Now that what I entered in Orion seems to work, the answer is: just look at the picture (ignore the text :slight_smile:). One thing to note: keys should be in double quotes.

0 Likes

#5

Thanks. Could you add something on how to enter expressions in Orion? I believe, for example, that one should not type in the keyword “expression” in Orion.

0 Likes

#6

I’m not too familiar with the Orion UI, but I’d guess these would work:

{id: "unitId"}
{"id": "unitId"}
{id: 'lumen'}
{id: "'lumen'"}
{"id": 'lumen'}
{"id": "'lumen'"}

Just an informed guess based on the resulting metadata from the transformations I posted above, which looks like this:

field0: {"id":"unitId"}
field1: {"id":"unitId"}
field2: {"id":"unitId"}
field3: {"id":"unitId"}
field4: {id: "unitId"}
field5: {id: 'unitId'} ⛔️
field6: {"id": "unitId"}
field8: {id: 'unitId'} ⛔️
field9: {id: "unitId"}
field10: {"id": 'unitId'} ⛔️
field13: {"id": "unitId"}
field14: {"id":"'lumen'"}
field17: {id: 'lumen'}
field18: {id: 'lumen'}
field19: {id: "'lumen'"}
field20: {id: "'lumen'"}
field21: {"id": 'lumen'}
field22: {"id": 'lumen'}
field23: {"id": "'lumen'"}
field24: {"id": "'lumen'"} ⛔️
field25: {id: '"lumen"'} ⛔️
field26: {id: '"lumen"'}
2 Likes