Using non alphanumeric characters in keys of NamedTuples

I can create a Symbol with spaces and other special characters e.g. complex = :"code-1 23"
I can use this Symbol as a key to a Hash, but so far I could not figure out how to use it as a key in a NamedTuple. Is it possible? How?

See my experiments:

macro t(name)
  print "%s %s\n" % {typeof({{name}}), {{name}}}
end

simple = :name
t simple
complex = :"code-1 23"
t complex

h = {simple => 1, complex => 2}
t h

nt = {name: "foo", complex: "bar"}
t nt
p nt["name"]
p nt[:name]
p nt[simple]
p nt["complex"]
p nt[:complex]
p nt[complex]
Symbol name
Symbol code-1 23
Hash(Symbol, Int32) {:name => 1, :"code-1 23" => 2}
NamedTuple(name: String, complex: String) {name: "foo", complex: "bar"}
"foo"
"foo"
"foo"
"bar"
"bar"
Unhandled exception: Missing named tuple key: :"code-1 23" (KeyError)
  from /usr/share/crystal/src/named_tuple.cr:122:18 in '[]'
  from z.cr:25:1 in '__crystal_main'
  from /usr/share/crystal/src/crystal/main.cr:110:5 in 'main_user_code'
  from /usr/share/crystal/src/crystal/main.cr:96:7 in 'main'
  from /usr/share/crystal/src/crystal/main.cr:119:3 in 'main'
  from __libc_start_main
  from _start
  from ???

Replying to myself: I am not sure what was I doing earlier but I succeeded in creating the NamedTuple:

macro t(name)
  print "%s %s\n" % {typeof({{name}}), {{name}}}
end

h = {a: 1, "a b-23": 2}
t h
h.each {|x, y|
  t x
  t y
}

However creating an alias for it and then using from_json still does not work:

require "json"
alias MyData = NamedTuple(
  a: Int32,
  "a b-23": Int32,
)
json_str = %{{"a": 1, "a b-23": 2}}
puts json_str
b = MyData.from_json(json_str)

Blew up with this:

There was a problem expanding macro 'macro_140629738106480'

Code in /usr/share/crystal/src/json/from_json.cr:212:3

 212 | {% begin %}
       ^
Called macro defined in /usr/share/crystal/src/json/from_json.cr:212:3

 212 | {% begin %}

Which expanded to:

 > 40 |         a: (__temp_626).as(Int32),
 > 41 |       
 > 42 |         a b-23: (__temp_628).as(Int32),
                ^
Error: expected '}' or named tuple name, not a

That’s a bug, please report it. Thank you!

done: parsing error in from_json of non alphanumeric fields · Issue #10918 · crystal-lang/crystal · GitHub