import json


def json_recursive_size(data, level=0, maxlevel=None):
    """Get size of a JSON object recursively."""

    ### HELPERS

    # how many levels remaining?
    remaining_levels = maxlevel - level if maxlevel is not None else None

    def length_now(d):
        """Get length of a json string."""
        return len(json.dumps(d))

    def subcall(**kwargs):
        """Call myself recursively."""
        return json_recursive_size(level=level + 1,
                                   maxlevel=maxlevel,
                                   **kwargs)

    if maxlevel is not None and level >= maxlevel:
        return length_now(d=data)

    if isinstance(data, dict):
        result = {}
        for key, value in data.items():
            result[key] = subcall(data=value)
    elif isinstance(data, list):
        result = []
        for val in data:
            result.append(subcall(data=val))
    else:
        result = length_now(d=data)

    return result