def as_json(self):
        """Translate to JSON.

        Returns
        -------
        :class:`dict`
            JSON representation of :attr:`origin` that describes its interface members and includes
            their annotations.
        """
        def translate_member(member, origin, *, path):
            assert isinstance(member, Member)
            if member.is_port:
                cast_shape = Shape.cast(member.shape)
                return {
                    "type": "port",
                    "name": "__".join(str(key) for key in path),
                    "dir": "in" if member.flow == In else "out",
                    "width": cast_shape.width,
                    "signed": cast_shape.signed,
                    "init": str(member._init_as_const.value),
                }
            elif member.is_signature:
                return {
                    "type": "interface",
                    "members": {
                        sub_name: translate_dimensions(sub.dimensions, sub,
                                                       getattr(origin, sub_name),
                                                       path=(*path, sub_name))
                        for sub_name, sub in member.signature.members.items()
                    },
                    "annotations": {
                        annotation.schema["$id"]: annotation.as_json()
                        for annotation in member.signature.annotations(origin)
                    },
                }
            else:
                assert False # :nocov:

        def translate_dimensions(dimensions, member, origin, *, path):
            if len(dimensions) == 0:
                return translate_member(member, origin, path=path)
            dimension, *rest_of_dimensions = dimensions
            return [
                translate_dimensions(rest_of_dimensions, member, origin[index],
                                     path=(*path, index))
                for index in range(dimension)
            ]

        instance = {
            "interface": {
                "members": {
                    member_name: translate_dimensions(member.dimensions, member,
                                                      getattr(self.origin, member_name),
                                                      path=(member_name,))
                    for member_name, member in self.origin.signature.members.items()
                },
                "annotations": {
                    annotation.schema["$id"]: annotation.as_json()
                    for annotation in self.origin.signature.annotations(self.origin)
                },
            },
        }
        self.validate(instance)
        return instance
Translate to JSON.

        Returns
        -------
        :class:`dict`
            JSON representation of :attr:`origin` that describes its interface members and includes
            their annotations.
        
amaranth/lib/wiring.py