diff options
Diffstat (limited to 'mitmproxy/contentviews/json.py')
-rw-r--r-- | mitmproxy/contentviews/json.py | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/mitmproxy/contentviews/json.py b/mitmproxy/contentviews/json.py index 7c128d02..de7f1093 100644 --- a/mitmproxy/contentviews/json.py +++ b/mitmproxy/contentviews/json.py @@ -1,7 +1,7 @@ import json from typing import Optional -from mitmproxy.contentviews.base import format_text, View +from mitmproxy.contentviews import base def pretty_json(s: bytes) -> Optional[bytes]: @@ -10,15 +10,10 @@ def pretty_json(s: bytes) -> Optional[bytes]: except ValueError: return None pretty = json.dumps(p, sort_keys=True, indent=4, ensure_ascii=False) - if isinstance(pretty, str): - # json.dumps _may_ decide to return unicode, if the JSON object is not ascii. - # From limited testing this is always valid utf8 (otherwise json.loads will fail earlier), - # so we can just re-encode it here. - return pretty.encode("utf8", "strict") - return pretty + return pretty.encode("utf8", "strict") -class ViewJSON(View): +class ViewJSON(base.View): name = "JSON" prompt = ("json", "s") content_types = [ @@ -29,4 +24,4 @@ class ViewJSON(View): def __call__(self, data, **metadata): pj = pretty_json(data) if pj: - return "JSON", format_text(pj) + return "JSON", base.format_text(pj) |