def write_libxc_docs_json(xcfuncs, jpath):
    """Write json file with libxc metadata to path jpath."""
    from copy import deepcopy
    xcfuncs = deepcopy(xcfuncs)

    # Remove XC_FAMILY from Family and XC_ from Kind to make strings more human-readable.
    for d in xcfuncs.values():
        d["Family"] = d["Family"].replace("XC_FAMILY_", "", 1)
        d["Kind"] = d["Kind"].replace("XC_", "", 1)

    # Build lightweight version with a subset of keys.
    for num, d in xcfuncs.items():
        xcfuncs[num] = {k: d[k] for k in ("Family", "Kind", "References")}
        # Descriptions are optional
        for opt in ("Description 1", "Description 2"):
            desc = d.get(opt)
            if desc is not None: xcfuncs[num][opt] = desc

    with open(jpath, "wt") as fh:
        json.dump(xcfuncs, fh)

    return xcfuncs