CodeSampleX

Пример

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

Проверенный пример — golang github.com/json-iterator/go v1.1.11: Get. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден.

sha256:fd9ecf920c9411ea3701ea800f4ce0f59ebc252af3c2b6ebde48e012cff8f9b8

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 go

Среды запусков проверки

Окружение Контракт Этапы Запуск
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

Кейс

HOW
Цель
verify pkg:golang/github.com/json-iterator/go@v1.1.11
Пакеты
Символы
  • github.com/json-iterator/go.Get
Создан
2026-09-04T23:22:39Z

Контракт

  1. jsoniter.Get extracts nested field values across mixed object and array paths without schema unmarshaling
  2. jsoniter.Get converts dynamically extracted JSON values to concrete string, integer, float, and boolean types
  3. jsoniter.Get inspects object keys and array length via Keys and Size methods
  4. jsoniter.Get reports non-nil LastError when attempting to navigate nonexistent paths
  5. jsoniter.Get accurately identifies underlying JSON value types including StringValue, NumberValue, ArrayValue, and ObjectValue

Файлы

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

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

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
Demonstrate these symbols/APIs:
  - github.com/json-iterator/go.Get

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:3e12742e3f61c7d42a1612532d0e96cb05495403c612d9f9438003fe1119ebc0","contract":["jsoniter.Get extracts nested field values across mixed object and array paths without schema unmarshaling","jsoniter.Get converts dynamically extracted JSON values to concrete string, integer, float, and boolean types","jsoniter.Get inspects object keys and array length via Keys and Size methods","jsoniter.Get reports non-nil LastError when attempting to navigate nonexistent paths","jsoniter.Get accurately identifies underlying JSON value types including StringValue, NumberValue, ArrayValue, and ObjectValue"],"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,"symbols":["github.com/json-iterator/go.Get"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","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","symbols":["github.com/json-iterator/go.Get"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
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 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
sample.go
package sample

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

// GetPath extracts a nested JSON element along the specified path keys or indices using jsoniter.Get.
func GetPath(data []byte, path ...interface{}) jsoniter.Any {
	return jsoniter.Get(data, path...)
}

// ExtractString resolves a string value at the target path.
func ExtractString(data []byte, path ...interface{}) (string, error) {
	val := jsoniter.Get(data, path...)
	if err := val.LastError(); err != nil {
		return "", err
	}
	return val.ToString(), nil
}

// ExtractInt resolves an integer value at the target path.
func ExtractInt(data []byte, path ...interface{}) (int, error) {
	val := jsoniter.Get(data, path...)
	if err := val.LastError(); err != nil {
		return 0, err
	}
	return val.ToInt(), nil
}

// ExtractFloat resolves a float64 value at the target path.
func ExtractFloat(data []byte, path ...interface{}) (float64, error) {
	val := jsoniter.Get(data, path...)
	if err := val.LastError(); err != nil {
		return 0, err
	}
	return val.ToFloat64(), nil
}

// ExtractBool resolves a boolean value at the target path.
func ExtractBool(data []byte, path ...interface{}) (bool, error) {
	val := jsoniter.Get(data, path...)
	if err := val.LastError(); err != nil {
		return false, err
	}
	return val.ToBool(), nil
}

// InspectKeys returns the keys for an object node at the target path.
func InspectKeys(data []byte, path ...interface{}) ([]string, error) {
	val := jsoniter.Get(data, path...)
	if err := val.LastError(); err != nil {
		return nil, err
	}
	return val.Keys(), nil
}

// InspectSize returns the number of elements in an array or object at the target path.
func InspectSize(data []byte, path ...interface{}) (int, error) {
	val := jsoniter.Get(data, path...)
	if err := val.LastError(); err != nil {
		return 0, err
	}
	return val.Size(), 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"
  ],
  "symbols": [
    "github.com/json-iterator/go.Get"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

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

func main() {
	// Contract 1: jsoniter.Get extracts nested field values across mixed object and array paths without schema unmarshaling
	{
		payload := []byte(`{
			"store": {
				"departments": [
					{
						"id": "dept-electronics",
						"manager": {"name": "Alice", "active": true}
					},
					{
						"id": "dept-books",
						"manager": {"name": "Bob", "active": false}
					}
				]
			}
		}`)

		dept0ID, err := sample.ExtractString(payload, "store", "departments", 0, "id")
		if err != nil || dept0ID != "dept-electronics" {
			fmt.Fprintf(os.Stderr, "FAIL [Contract 1]: expected dept-electronics, got %q (err: %v)\n", dept0ID, err)
			os.Exit(1)
		}

		mgr1Name, err := sample.ExtractString(payload, "store", "departments", 1, "manager", "name")
		if err != nil || mgr1Name != "Bob" {
			fmt.Fprintf(os.Stderr, "FAIL [Contract 1]: expected Bob, got %q (err: %v)\n", mgr1Name, err)
			os.Exit(1)
		}
	}

	// Contract 2: jsoniter.Get converts dynamically extracted JSON values to concrete string, integer, float, and boolean types
	{
		payload := []byte(`{
			"item": {
				"title": "Widget",
				"quantity": 42,
				"price": 19.99,
				"in_stock": true
			}
		}`)

		title, err := sample.ExtractString(payload, "item", "title")
		if err != nil || title != "Widget" {
			fmt.Fprintf(os.Stderr, "FAIL [Contract 2]: title mismatch: %q (err: %v)\n", title, err)
			os.Exit(1)
		}

		quantity, err := sample.ExtractInt(payload, "item", "quantity")
		if err != nil || quantity != 42 {
			fmt.Fprintf(os.Stderr, "FAIL [Contract 2]: quantity mismatch: %d (err: %v)\n", quantity, err)
			os.Exit(1)
		}

		price, err := sample.ExtractFloat(payload, "item", "price")
		if err != nil || price != 19.99 {
			fmt.Fprintf(os.Stderr, "FAIL [Contract 2]: price mismatch: %f (err: %v)\n", price, err)
			os.Exit(1)
		}

		inStock, err := sample.ExtractBool(payload, "item", "in_stock")
		if err != nil || inStock != true {
			fmt.Fprintf(os.Stderr, "FAIL [Contract 2]: in_stock mismatch: %v (err: %v)\n", inStock, err)
			os.Exit(1)
		}
	}

	// Contract 3: jsoniter.Get inspects object keys and array length via Keys and Size methods
	{
		payload := []byte(`{
			"tags": ["alpha", "beta", "gamma"],
			"config": {
				"timeout": 30,
				"retries": 3
			}
		}`)

		size, err := sample.InspectSize(payload, "tags")
		if err != nil || size != 3 {
			fmt.Fprintf(os.Stderr, "FAIL [Contract 3]: tags size mismatch: %d (err: %v)\n", size, err)
			os.Exit(1)
		}

		keys, err := sample.InspectKeys(payload, "config")
		if err != nil {
			fmt.Fprintf(os.Stderr, "FAIL [Contract 3]: InspectKeys error: %v\n", err)
			os.Exit(1)
		}
		expectedKeys := []string{"timeout", "retries"}
		if len(keys) != len(expectedKeys) {
			fmt.Fprintf(os.Stderr, "FAIL [Contract 3]: expected keys %v, got %v\n", expectedKeys, keys)
			os.Exit(1)
		}
		found := make(map[string]bool)
		for _, k := range keys {
			found[k] = true
		}
		if !found["timeout"] || !found["retries"] {
			fmt.Fprintf(os.Stderr, "FAIL [Contract 3]: missing expected keys: %v\n", keys)
			os.Exit(1)
		}
	}

	// Contract 4: jsoniter.Get reports non-nil LastError when attempting to navigate nonexistent paths
	{
		payload := []byte(`{"status": "ok"}`)

		val := sample.GetPath(payload, "nonexistent_field")
		if val.LastError() == nil {
			fmt.Fprintf(os.Stderr, "FAIL [Contract 4]: expected non-nil LastError for nonexistent path, got nil\n")
			os.Exit(1)
		}

		nestedMissing := sample.GetPath(payload, "status", "nested_missing")
		if nestedMissing.LastError() == nil {
			fmt.Fprintf(os.Stderr, "FAIL [Contract 4]: expected non-nil LastError for nested nonexistent path, got nil\n")
			os.Exit(1)
		}
	}

	// Contract 5: jsoniter.Get accurately identifies underlying JSON value types including StringValue, NumberValue, ArrayValue, and ObjectValue
	{
		payload := []byte(`{
			"str": "text",
			"num": 123,
			"arr": [1, 2],
			"obj": {"nested": true}
		}`)

		if vt := sample.GetPath(payload, "str").ValueType(); vt != jsoniter.StringValue {
			fmt.Fprintf(os.Stderr, "FAIL [Contract 5]: expected StringValue, got %v\n", vt)
			os.Exit(1)
		}
		if vt := sample.GetPath(payload, "num").ValueType(); vt != jsoniter.NumberValue {
			fmt.Fprintf(os.Stderr, "FAIL [Contract 5]: expected NumberValue, got %v\n", vt)
			os.Exit(1)
		}
		if vt := sample.GetPath(payload, "arr").ValueType(); vt != jsoniter.ArrayValue {
			fmt.Fprintf(os.Stderr, "FAIL [Contract 5]: expected ArrayValue, got %v\n", vt)
			os.Exit(1)
		}
		if vt := sample.GetPath(payload, "obj").ValueType(); vt != jsoniter.ObjectValue {
			fmt.Fprintf(os.Stderr, "FAIL [Contract 5]: expected ObjectValue, got %v\n", vt)
			os.Exit(1)
		}
	}

	// Direct call on jsoniter.Get to establish direct symbol linkage
	{
		val := jsoniter.Get([]byte(`{"verified": true}`), "verified")
		if !val.ToBool() {
			fmt.Fprintf(os.Stderr, "FAIL: direct jsoniter.Get call failed\n")
			os.Exit(1)
		}
	}

	fmt.Println("PASS: all pkg:golang/github.com/json-iterator/go@v1.1.11 contracts verified successfully")
}

Исходный сидер

аноним