<｜begin▁of▁sentence｜>### Instruction:
Given a GN graph with n nodes, where nodes join the network one at a time by linking to a previously added node based on a probability proportional to the degree of the existing nodes, could you produce a JSON representation of the graph where each node has an 'id' and 'label', and each edge identifies its 'source', 'target', and 'label'?
### Response:
import networkx as nx

# Function to generate a GN graph
def generate_gn_graph(n, kernel=None, seed=None):
    # Create a GN graph
    G = nx.gn_graph(n, kernel=kernel, seed=seed)
    # Convert the graph to the undirected version if needed
    G_undirected = G.to_undirected()
    
    # Generate the JSON representation
    json_graph = {'graph nodes': [], 'graph edges': []}
    
    for node in G_undirected.nodes():
        json_graph['graph nodes'].append({'id': node, 'label': f'Node {node}'})
    
    for edge in G_undirected.edges():
        json_graph['graph edges'].append({'source': edge[0], 'target': edge[1], 'label': f'Edge from {edge[0]} to {edge[1]}'})
    
    return json_graph

# Example: Generate a GN graph with 5 nodes
graph_json = generate_gn_graph(5)
print(graph_json)
<|EOT|>
