'Return a single node as JSON (id, parent and label)
@param r: the S3Request
@param attr: controller attributes'

def node_json(self, r, **attr):

    resource = self.resource
    tablename = resource.tablename
    h = S3Hierarchy(tablename=tablename)
    if (not h.config):
        r.error(405, ('No    hierarchy    configured    for    %s' % tablename))
    data = {}
    node_id = r.get_vars['node']
    if node_id:
        try:
            node_id = long(node_id)
        except ValueError:
            pass
        else:
            data['node'] = node_id
            label = h.label(node_id)
            data['label'] = (label if label else None)
            data['parent'] = h.parent(node_id)
            children = h.children(node_id)
            if children:
                nodes = []
                h._represent(node_ids=children)
                for child_id in children:
                    label = h.label(child_id)
                    nodes.append({'node': child_id, 'label': (label if label else None)})
                data['children'] = nodes
    current.response.headers['Content-Type'] = 'application/json'
    return json.dumps(data, separators=SEPARATORS)
