jsonutil

package
v0.75.3 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: MIT Imports: 4 Imported by: 0

README

jsonutil Package

Compact JSON marshaling utilities that avoid HTML escaping for safe expression handling.

Overview

The jsonutil package provides a thin wrapper around Go's standard encoding/json encoder to produce compact JSON output without HTML escaping. This is essential for serializing GitHub Actions expressions (e.g. ${{ env.X && env.Y }}) that contain characters such as &, <, and > which the standard json.Marshal would otherwise encode as \u0026, \u003c, and \u003e.

Public API

Functions
Function Signature Description
MarshalCompactNoHTMLEscape func(v any) (string, error) Marshals v to compact JSON without HTML escaping, trimming the trailing newline emitted by json.Encoder

Usage Examples

import "github.com/github/gh-aw/pkg/jsonutil"

data := map[string]string{
    "expr": "${{ env.MCP_ENV == 'staging' && env.MCP_URL_STAGING || env.MCP_URL_PROD }}",
}

result, err := jsonutil.MarshalCompactNoHTMLEscape(data)
if err != nil {
    return fmt.Errorf("failed to marshal: %w", err)
}
// result: {"expr":"${{ env.MCP_ENV == 'staging' && env.MCP_URL_STAGING || env.MCP_URL_PROD }}"}
// Note: '&&' and '||' are preserved — not escaped to \u0026\u0026 or \u007c\u007c

Dependencies

Internal:

  • github.com/github/gh-aw/pkg/logger — package-scoped logger used for marshal error diagnostics

Design Notes

  • Uses json.Encoder with SetEscapeHTML(false) rather than json.Marshal to suppress HTML escaping.
  • The trailing newline that json.Encoder.Encode appends is trimmed with strings.TrimSuffix so the result is consistent with json.Marshal output.
  • The package has no external dependencies beyond the Go standard library.

This specification is automatically maintained by the spec-extractor workflow.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalCompactNoHTMLEscape

func MarshalCompactNoHTMLEscape(v any) (string, error)

MarshalCompactNoHTMLEscape marshals a value to compact JSON without HTML escaping. It trims the trailing newline emitted by json.Encoder.

Types

This section is empty.

Jump to

Keyboard shortcuts

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