ClaudeCodeSDK.JSON (claude_code_sdk v0.0.1)

View Source

Simple JSON parser for Claude Code SDK.

This module provides a lightweight JSON decoder that doesn't require external dependencies. It first attempts to use Erlang's built-in :json module (OTP 27+), falling back to a manual parser for older versions.

The manual parser handles the basic JSON structures needed for Claude Code messages:

  • Objects (maps)
  • Arrays (lists)
  • Strings
  • Numbers (integers and floats)
  • Booleans and null

Note: The manual parser is simplified and may not handle all edge cases of the JSON specification, but it's sufficient for parsing Claude Code CLI output.

Summary

Functions

Decode a JSON string into an Elixir term.

Functions

decode(json_string)

@spec decode(String.t()) :: {:ok, term()} | {:error, :invalid_json}

Decode a JSON string into an Elixir term.

Parameters

  • json_string - A valid JSON string to decode

Returns

  • {:ok, term} - Successfully decoded JSON as Elixir term
  • {:error, :invalid_json} - Failed to parse JSON

Examples

iex> ClaudeCodeSDK.JSON.decode(~s({"key": "value"}))
{:ok, %{"key" => "value"}}

iex> ClaudeCodeSDK.JSON.decode(~s([1, 2, 3]))
{:ok, [1, 2, 3]}

iex> ClaudeCodeSDK.JSON.decode("invalid")
{:error, :invalid_json}