Postel's law and parsing ActivityPub data: a question about JSON-LD flattening

Postel’s law saws “be liberal in what you accept from others”, but how liberal should an ActivityPub consumer be?

The JSON-LD 1.1 spec says

Flattening collects all properties of a node in a single map and labels all blank nodes with blank node identifiers. This ensures a shape of the data and consequently may drastically simplify the code required to process JSON-LD in certain applications.

…so I was thinking that flattening would help with making an ActivityPub consumer somewhat forgiving.

However, I’ve noticed that flattening turns property values into arrays. For example, this…

{
  "@context": "https://www.w3.org/ns/activitystreams",
  "id": "https://example.org/person",
  "name": "Foo"
}

…flattens into this…

[
  {
    "@id": "https://example.org/person",
    "https://www.w3.org/ns/activitystreams#name": [
      {
        "@value": "Foo"
      }
    ]
  }
]

Note that the value of the name property is now an array.

So what’s the right thing to do if this array has more than one element? Should I use one of the elements (and if so, which one?), should I treat it as being unset, or something else?

Certain properties are marked “functional” and can only have one value. Other properties are technically arrays even if they only have one value. You may wish to take the first value, or perhaps develop some other strategy for picking a suitable value out of the array based on what your software understands.

Thanks! I hadn’t noticed the note about “functional” properties.

So if I understand right, you’re saying that using the first value if multiple appear for a functional property is pretty reasonable?

In terms of non-functional properties, I’m surprised that certain properties are allowed to have multiple values. For example I’d mistakenly thought that name would be single-value, but from the spec it looks like it is not “functional”, and so multiple values are allowed. What does it mean for an Object to have multiple names?

I suppose it would mean something similar to having multiple names IRL? For most practical uses, you would use nameMap for multiple languages, though.

1 Like