rawjson

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package rawjson provides a safe raw JSON byte type for workflow boundaries.

Motivation

Go's json.RawMessage implements json.Marshaler and treats a non-nil empty slice as invalid JSON, returning: "json: error calling MarshalJSON for type json.RawMessage: unexpected end of JSON input".

In this runtime, raw JSON byte fields are intentionally used at workflow and activity boundaries (tool payloads/results, hook envelopes, server-data sidecars). A single accidental `json.RawMessage{}` or `[]byte{}` assignment can therefore crash workflow encoding.

Message eliminates that failure mode by normalizing empty/whitespace payloads to JSON null during marshaling while still validating non-empty payloads.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message json.RawMessage

Message is an opaque JSON value encoded as bytes.

Contract:

  • Nil represents absence (preferred).
  • Non-empty values must be valid JSON.
  • Empty/whitespace-only values are normalized to JSON null during marshaling to avoid runtime encoding failures at workflow boundaries.

func (Message) MarshalJSON

func (r Message) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

This method never returns an "unexpected end of JSON input" error for empty slices; empty/whitespace is encoded as JSON null.

func (Message) RawMessage

func (r Message) RawMessage() json.RawMessage

RawMessage returns the underlying value as json.RawMessage.

func (*Message) UnmarshalJSON

func (r *Message) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

The decoder validates non-null JSON and normalizes null to nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL