CodeSampleX

Ejemplo

github.com/json-iterator/go v1.1.11

Muestra verificada para golang github.com/json-iterator/go v1.1.11. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y pasó.

sha256:225e970f431b5fe033d338560077a33bb13949553ab29316f5c2609ae46a80e0

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 go go

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-04

Caso

HOW
Objetivo
verify pkg:golang/github.com/json-iterator/go@v1.1.11
Paquetes
Creado
2026-09-04T23:07:42Z

Contrato

  1. jsoniter.ConfigCompatibleWithStandardLibrary.Marshal serializes structs and slices into valid JSON bytes
  2. jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal deserializes JSON bytes into structured Go types
  3. jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal returns error on malformed or truncated JSON input
  4. jsoniter.ConfigCompatibleWithStandardLibrary.NewEncoder and NewDecoder handle streaming JSON encoding and decoding using More
  5. jsoniter.Get navigates and extracts nested properties and array elements dynamically without schemas
  6. jsoniter.Marshal and jsoniter.Unmarshal serialize and deserialize standard structs directly

Archivos

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • jsoniter_example.go
  • spec.json
  • test/contract.go

Descargar el artefacto de código fuente (tar.gz)

Código fuente

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:golang/github.com/json-iterator/go@v1.1.11
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/json-iterator/go@v1.1.11

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:3c0f07447114adda70a7d8f0a21a9bc90a06634a9726e4e8ea06d1b41cc5dbe9","contract":["jsoniter.ConfigCompatibleWithStandardLibrary.Marshal serializes structs and slices into valid JSON bytes","jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal deserializes JSON bytes into structured Go types","jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal returns error on malformed or truncated JSON input","jsoniter.ConfigCompatibleWithStandardLibrary.NewEncoder and NewDecoder handle streaming JSON encoding and decoding using More","jsoniter.Get navigates and extracts nested properties and array elements dynamically without schemas","jsoniter.Marshal and jsoniter.Unmarshal serialize and deserialize standard structs directly"],"goal":"verify pkg:golang/github.com/json-iterator/go@v1.1.11","kind":"HOW","packages":["pkg:golang/github.com/json-iterator/go@v1.1.11"],"schemaVersion":1},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/json-iterator/go@v1.1.11"],"schemaVersion":1,"subject":"pkg:golang/github.com/json-iterator/go@v1.1.11","verifierAdapter":"golang@1"}
go.mod
module example.com/jsoniter-sample

go 1.22.0

require github.com/json-iterator/go v1.1.11

require (
	github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
	github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
)
go.sum
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ=
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
jsoniter_example.go
package jsoniterexample

import (
	"io"

	jsoniter "github.com/json-iterator/go"
)

// User represents a sample data structure for JSON serialization.
type User struct {
	ID    int      `json:"id"`
	Name  string   `json:"name"`
	Roles []string `json:"roles"`
}

var json = jsoniter.ConfigCompatibleWithStandardLibrary

// SerializeUser encodes a User struct into JSON bytes.
func SerializeUser(u User) ([]byte, error) {
	return json.Marshal(u)
}

// DeserializeUser decodes JSON bytes into a User struct.
func DeserializeUser(data []byte) (User, error) {
	var u User
	err := json.Unmarshal(data, &u)
	return u, err
}

// StreamEncodeUsers writes multiple User structs as a JSON stream.
func StreamEncodeUsers(w io.Writer, users []User) error {
	enc := json.NewEncoder(w)
	for _, u := range users {
		if err := enc.Encode(u); err != nil {
			return err
		}
	}
	return nil
}

// StreamDecodeUsers reads User structs from a streaming JSON input.
func StreamDecodeUsers(r io.Reader) ([]User, error) {
	dec := json.NewDecoder(r)
	var users []User
	for dec.More() {
		var u User
		if err := dec.Decode(&u); err != nil {
			return nil, err
		}
		users = append(users, u)
	}
	return users, nil
}

// ExtractStringField navigates JSON structure dynamically without schema.
func ExtractStringField(data []byte, path ...interface{}) (string, error) {
	val := jsoniter.Get(data, path...)
	if err := val.LastError(); err != nil {
		return "", err
	}
	return val.ToString(), nil
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/json-iterator/go@v1.1.11",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/json-iterator/go@v1.1.11"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

	jsoniterexample "example.com/jsoniter-sample"
	jsoniter "github.com/json-iterator/go"
)

func main() {
	if err := runContractTests(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("PASS: all json-iterator contracts verified")
}

func runContractTests() error {
	// Contract 1: jsoniter.ConfigCompatibleWithStandardLibrary.Marshal serializes structs and slices into valid JSON bytes
	u := jsoniterexample.User{
		ID:    101,
		Name:  "TestUser",
		Roles: []string{"admin", "editor"},
	}
	data, err := jsoniterexample.SerializeUser(u)
	if err != nil {
		return fmt.Errorf("SerializeUser failed: %w", err)
	}
	expectedJSON := `{"id":101,"name":"TestUser","roles":["admin","editor"]}`
	if string(data) != expectedJSON {
		return fmt.Errorf("Marshal output mismatch: got %s, want %s", string(data), expectedJSON)
	}

	// Contract 2: jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal deserializes JSON bytes into structured Go types
	decoded, err := jsoniterexample.DeserializeUser(data)
	if err != nil {
		return fmt.Errorf("DeserializeUser failed: %w", err)
	}
	if decoded.ID != 101 || decoded.Name != "TestUser" || len(decoded.Roles) != 2 || decoded.Roles[0] != "admin" || decoded.Roles[1] != "editor" {
		return fmt.Errorf("Unmarshal data mismatch: %+v", decoded)
	}

	// Contract 3: jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal returns error on malformed or truncated JSON input
	malformedJSON := []byte(`{"id": 101, "name": "Broken"`)
	if _, err := jsoniterexample.DeserializeUser(malformedJSON); err == nil {
		return fmt.Errorf("expected error when unmarshaling malformed JSON, got nil")
	}

	// Contract 4: jsoniter.ConfigCompatibleWithStandardLibrary.NewEncoder and NewDecoder handle streaming JSON encoding and decoding using More
	users := []jsoniterexample.User{
		{ID: 1, Name: "Alice", Roles: []string{"viewer"}},
		{ID: 2, Name: "Bob", Roles: []string{"contributor"}},
	}
	var streamBuf bytes.Buffer
	if err := jsoniterexample.StreamEncodeUsers(&streamBuf, users); err != nil {
		return fmt.Errorf("StreamEncodeUsers failed: %w", err)
	}
	streamDecoded, err := jsoniterexample.StreamDecodeUsers(&streamBuf)
	if err != nil {
		return fmt.Errorf("StreamDecodeUsers failed: %w", err)
	}
	if len(streamDecoded) != 2 || streamDecoded[0].Name != "Alice" || streamDecoded[1].Name != "Bob" {
		return fmt.Errorf("StreamDecodeUsers mismatch: %+v", streamDecoded)
	}

	// Contract 5: jsoniter.Get navigates and extracts nested properties and array elements dynamically without schemas
	nestedJSON := []byte(`{"catalog":{"items":[{"name":"ItemA","price":25},{"name":"ItemB","price":40}]}}`)
	itemName, err := jsoniterexample.ExtractStringField(nestedJSON, "catalog", "items", 1, "name")
	if err != nil {
		return fmt.Errorf("ExtractStringField failed: %w", err)
	}
	if itemName != "ItemB" {
		return fmt.Errorf("expected itemName 'ItemB', got '%s'", itemName)
	}
	if _, err := jsoniterexample.ExtractStringField(nestedJSON, "catalog", "nonexistent"); err == nil {
		return fmt.Errorf("expected error for non-existent field, got nil")
	}

	// Contract 6: jsoniter.Marshal and jsoniter.Unmarshal serialize and deserialize standard structs directly
	directBytes, err := jsoniter.Marshal(u)
	if err != nil {
		return fmt.Errorf("direct jsoniter.Marshal failed: %w", err)
	}
	var directUser jsoniterexample.User
	if err := jsoniter.Unmarshal(directBytes, &directUser); err != nil {
		return fmt.Errorf("direct jsoniter.Unmarshal failed: %w", err)
	}
	if directUser.ID != 101 || directUser.Name != "TestUser" {
		return fmt.Errorf("direct result mismatch: %+v", directUser)
	}

	return nil
}

Seeder de origen

anónimo