lanthaler / JsonLD

JSON-LD processor for PHP
MIT License
335 stars 62 forks source link

JSON-LD always framing single object as array #77

Closed cleanunicorn closed 7 years ago

cleanunicorn commented 7 years ago

Is there a way to always force single objects to arrays?

If there are multiple values as rdf:type I get an array like this one. Note the @type property is an array.

    {
        "@context": {
            "ethon": "http://ethon.consensys.net/",
            "ethstats": "http://ethereum.ethstats.io/"
        },
        "@graph": [{
            "@id": "ethstats:Uncle_0x5cd50096dbb856a6d1befa6de8f9c20decb299f375154427d90761dc0b101109",
            "@type": ["ethon:Uncle", "ethon:Block"],
            "ethon:blockCreationTime": "2015-07-30T15:26:58.000Z",
            "ethon:blockHash": "0x5cd50096dbb856a6d1befa6de8f9c20decb299f375154427d90761dc0b101109",
            "ethon:number": "1"
        }]
    }

But if there is only one rdf:type the @type property is not an array.

    {
        "@context": {
            "ethon": "http://ethon.consensys.net/",
            "ethstats": "http://ethereum.ethstats.io/"
        },
        "@graph": [{
            "@id": "ethstats:Uncle_0x5cd50096dbb856a6d1befa6de8f9c20decb299f375154427d90761dc0b101109",
            "@type": "ethon:Uncle",
            "ethon:blockCreationTime": "2015-07-30T15:26:58.000Z",
            "ethon:blockHash": "0x5cd50096dbb856a6d1befa6de8f9c20decb299f375154427d90761dc0b101109",
            "ethon:number": "1"
        }]
    }

When serializing the graph, I send the options

    'frame' => (object) [
        '@context' => (object) [
            'ethon' => 'http://ethon.consensys.net/',
            'ethstats' => 'http://ethereum.ethstats.io/',
    ],

Is there a way to send the @set option for the rdf:type / @type property?

lanthaler commented 7 years ago

Yeah, the compactArrays option should do just that