MCPcopy Create free account
hub / github.com/AQ-MedAI/MedMemoryBench / parse_json

Function parse_json

methods/letta/utils.py:822–840  ·  view source on GitHub ↗

Parse JSON string into JSON with both json and demjson

(string)

Source from the content-addressed store, hash-verified

820
821
822def parse_json(string) -> dict:
823 """Parse JSON string into JSON with both json and demjson"""
824 result = None
825 try:
826 result = json_loads(string)
827 if not isinstance(result, dict):
828 raise ValueError(f"JSON from string input ({string}) is not a dictionary (type {type(result)}): {result}")
829 return result
830 except Exception as e:
831 print(f"Error parsing json with json package, falling back to demjson: {e}")
832
833 try:
834 result = demjson.decode(string)
835 if not isinstance(result, dict):
836 raise ValueError(f"JSON from string input ({string}) is not a dictionary (type {type(result)}): {result}")
837 return result
838 except demjson.JSONDecodeError as e:
839 print(f"Error parsing json with demjson package (fatal): {e}")
840 raise e
841
842
843def validate_function_response(function_response_string: any, return_char_limit: int, strict: bool = False, truncate: bool = True) -> str:

Callers 8

_handle_ai_responseMethod · 0.90
function_messageMethod · 0.90
to_letta_messageMethod · 0.90
to_anthropic_dictMethod · 0.90
to_google_ai_dictMethod · 0.90
to_cohere_dictMethod · 0.90

Calls 2

json_loadsFunction · 0.90
decodeMethod · 0.45

Tested by

no test coverage detected