<｜begin▁of▁sentence｜>### Instruction:
Given the Power Grid Graph which you can read from a GML file named power.gml, can you use the Infomap function in cdlib to perform community detection? And can you generate a JSON representation of the discovered communities?
### Response:
import networkx as nx
from cdlib import algorithms

# Read the power grid graph
G = nx.read_gml('power.gml')

# Perform community detection using the Infomap algorithm
coms = algorithms.infomap(G, flags='--two-level')

# Generate a JSON representation of the detected communities
coms_json = coms.to_json()

print(coms_json)
<|EOT|>
