How to define a map in cypher where the key value includes a hyphen?

I'm trying to define a map where one of the key values includes a hyphen. This is a very simple example:

WITH {non-production:'nonprod'} as envmap
return envmap

Doing this returns an error:

Invalid input '-': expected an identifier character, whitespace, '}' or ':' (line 1, column 10 (offset: 9))
"WITH {non-production:'nonprod'} as envmap"

This works fine when the key value does not require a hyphen, such as:

WITH {nonproduction:'nonprod'} as envmap
return envmap

But I need the hyphen in there. I've tried escaping the hyphen, such as:

WITH {non\-production:'nonprod'} as envmap
return envmap

But that still results in a syntax error, this time pointing at the escape character instead of at the hyphen. I tried with two escape sequence characters, same result. I thought perhaps trying to create another variable with that value then using the variable name might help, such as in:

WITH 'non-production' as np, {np:'nonprod'} as envmap
return envmap

While that gets rid of the syntax error, it uses 'np' as the key value, it does not use the value of the np variable.

How is a key value which contains a hyphen specified in a map?

You can do it with back ticks:

WITH {`non-production`:'nonprod'} as envmap
return envmap

Enclose non-production between backticks;
WITH {`non-production`:'nonprod'} as envmap
return envmap

Thank you! That looks like it will do it! :slightly_smiling_face:

Thank you Mark! That looks like it will work! :slightly_smiling_face: