Explore Library
Code QuizIntermediate

Parsing LLM JSON Output

Spot why parsing an LLM's JSON reply crashes on real responses.

Codejavascript
function parseLLMOutput(response) {
  // response is the raw text from the model
  const data = JSON.parse(response);
  return data;
}

const raw = "```json\n{\"name\": \"Ada\"}\n```";
console.log(parseLLMOutput(raw));

Why does this fail on typical LLM responses?