simplejsonmatch

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

README

simplejsonmatch

Go port of simple-json-match - a JSON schema matching library.

Test Case Port

Tests are generated programmatically from the JS source using generate_test.js.

Source
Test Counts
Category Count Notes
Main tests (implemented) 108 From JS tests array
Main tests (skipped) 13 $ref tests - not implemented
Not tests 12 From JS not_tests array
$not inversion 108 Each implemented test also run with {$not: schema}
Total 241 108×2 + 12 + 13 skipped
Regenerating Tests

To regenerate match_test.go from the JS source:

node generate_test.js > match_test.go

Operators Supported

Operator Description Status
$eq Deep equality
$neq Deep inequality
$gt Greater than
$gte Greater than or equal
$lt Less than
$lte Less than or equal
$in Substring or array membership
$nin Negated membership
$startsWith String prefix
$endsWith String suffix
$exist Field presence check
$or Logical OR
$and Logical AND
$not Logical NOT
$ref Field reference ❌ Not implemented
Why $ref is not implemented

The $ref operator allows comparing a field's value against another field in the same document. It was omitted because:

  • Limited use cases
  • Adds complexity with JSONPath-like parsing

Usage

import "github.com/hookdeck/outpost/internal/simplejsonmatch"

// Basic matching
input := map[string]any{"type": "created", "count": 5}
schema := map[string]any{"type": "created", "count": map[string]any{"$gte": 1}}

if simplejsonmatch.Match(input, schema) {
    // Input matches the schema
}

Documentation

Overview

Package simplejsonmatch provides JSON schema matching functionality. It is a Go port of the simple-json-match TypeScript library. https://github.com/hookdeck/simple-json-match

Index

Constants

View Source
const (
	OpEq         = "$eq"
	OpNeq        = "$neq"
	OpGt         = "$gt"
	OpGte        = "$gte"
	OpLt         = "$lt"
	OpLte        = "$lte"
	OpIn         = "$in"
	OpNin        = "$nin"
	OpStartsWith = "$startsWith"
	OpEndsWith   = "$endsWith"
	OpExist      = "$exist"
	OpOr         = "$or"
	OpAnd        = "$and"
	OpNot        = "$not"
)

Operator constants for schema matching.

Variables

View Source
var (
	ErrUnsupportedType = errors.New("unsupported type for operator")
)

Functions

func Match

func Match(input, schema any) bool

Match checks if the input JSON matches the given schema. Returns true if the input matches the schema, false otherwise.

Types

type JSONType

type JSONType string

JSONType represents the type of a JSON value.

const (
	JSONTypeNull      JSONType = "null"
	JSONTypeString    JSONType = "string"
	JSONTypeNumber    JSONType = "number"
	JSONTypeBoolean   JSONType = "boolean"
	JSONTypeObject    JSONType = "object"
	JSONTypeArray     JSONType = "array"
	JSONTypeUndefined JSONType = "undefined"
)

Jump to

Keyboard shortcuts

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