Is there a data serialization language that allows objects to be used as the name for another object?

213 views Asked by At

I have found JSON and YAML both lacking.

I wish to do something like this (in YAML):

nodes:
  node: "name for my node":
    - data
    - for 
    - this
    - node

(in JSON):

{"nodes":
   {"node":"name for my node": {
     ["data","for","this","node"] 
   }}
}

But these are both invalid in those data serialization languages.

Does anyone know of a data serialization language where you can use an object as the name for an object, basically? I think it's stupid that you can't do it in YAML, though I could forgive JSON since it is designed to be simple as opposed to being flexible.

1

There are 1 answers

1
michaelb958--GoFundMonica On

Actually, YAML can do that. Try the complex-key syntax (see the bottom of spec section 2.2)

nodes:
  ? node: name for my node
  : - data
    - for
    - this
    - node

That's a map with a single key, used as a key. If you perhaps were after a list as the key:

nodes:
  ? - nodename1
    - nodename2
  : - data
    - for
    - this
    - node