MCPcopy Index your code
hub / github.com/httpie/cli / format_body

Method format_body

httpie/output/formatters/json.py:12–34  ·  view source on GitHub ↗
(self, body: str, mime: str)

Source from the content-addressed store, hash-verified

10 self.enabled = self.format_options['json']['format']
11
12 def format_body(self, body: str, mime: str) -> str:
13 maybe_json = [
14 'json',
15 'javascript',
16 'text',
17 ]
18 if (self.kwargs['explicit_json']
19 or any(token in mime for token in maybe_json)):
20 from ..utils import load_prefixed_json
21 try:
22 data_prefix, json_obj = load_prefixed_json(body)
23 except ValueError:
24 pass # Invalid JSON, ignore.
25 else:
26 # Indent, sort keys by name, and avoid
27 # unicode escapes to improve readability.
28 body = data_prefix + json.dumps(
29 obj=json_obj,
30 sort_keys=self.format_options['json']['sort_keys'],
31 ensure_ascii=False,
32 indent=self.format_options['json']['indent']
33 )
34 return body

Callers

nothing calls this directly

Calls 1

load_prefixed_jsonFunction · 0.85

Tested by

no test coverage detected