public function flatten($element)
    {
        $nodeMap = new JsonObject();
        $nodeMap->{'-' . JsonLD::DEFAULT_GRAPH} = new JsonObject();

        $this->generateNodeMap($nodeMap, $element);

        $defaultGraph = $nodeMap->{'-' . JsonLD::DEFAULT_GRAPH};
        unset($nodeMap->{'-' . JsonLD::DEFAULT_GRAPH});

        // Store named graphs in the @graph property of the node representing
        // the graph in the default graph
        foreach ($nodeMap as $graphName => $graph) {
            if (!isset($defaultGraph->{$graphName})) {
                $defaultGraph->{$graphName} = new JsonObject();
                $defaultGraph->{$graphName}->{'@id'} = substr($graphName, 1);
            }

            $graph = (array) $graph;
            ksort($graph);
            $defaultGraph->{$graphName}->{'@graph'} = array_values(
                array_filter($graph, array($this, 'hasNodeProperties'))
            );
        }

        $defaultGraph = (array) $defaultGraph;
        ksort($defaultGraph);

        return array_values(
            array_filter($defaultGraph, array($this, 'hasNodeProperties'))
        );
    }