Categorygithub.com/bombsimon/jtd-infer-go
modulepackage
0.1.0
Repository: https://github.com/bombsimon/jtd-infer-go.git
Documentation: pkg.go.dev

# README

JSON typedef infer

Go Reference Build and test

This is a port of json-typedef-infer for Go. The reason for porting this is that I was in need of JTD inference from code and not as a CLI tool.

For more information about JSON Typedef and its RFC and how to use different kind of hints see json-typedef-infer.

Usage

See examples directory for runnable examples and how to infer JTD.

schema := NewInferrer(WithoutHints()).
    Infer("my-string").
    IntoSchema()
// {
//   "type": "string"
// }

If you have multiple rows of objects or lists as strings you can pass them to the shorthand function InferStrings.

rows := []string{
    `{"name":"Joe", "age": 52, "something_optional": true, "something_nullable": 1.1}`,
    `{"name":"Jane", "age": 48, "something_nullable": null}`,
}
schema := InferStrings(rows, WithoutHints()).IntoSchema()
// {
//   "properties": {
//     "age": {
//       "type": "uint8"
//     },
//     "name": {
//       "type": "string"
//     },
//     "something_nullable": {
//       "nullable": true,
//       "type": "float64"
//     }
//   },
//   "optionalProperties": {
//     "something_optional": {
//       "type": "boolean"
//     }
//   }
// }

# Packages

No description provided by the author

# Functions

InferStrings accepts a slice of strings and will try to JSON unmarshal each row.
NewHintSet creates a new empty `HintSet`.
NewInferredSchema will return a new, empty, `InferredSchema`.
NewInferrer will create a new inferrer with a default `InferredSchema`.
NewNumber will return a new `InferredNumber`.
WithoutHints is a shorthand to return empty hints.

# Constants

Available number types.
Available number types.
Available number types.
Available number types.
Available number types.
Available number types.
Available number types.
Available number types.
Available schema types.
Available schema types.
Available schema types.
Available schema types.
Available schema types.
Available schema types.
Available schema types.
Available schema types.
Available schema types.
Available schema types.
Available schema types.
Available schema types.
Wildcard represents the character that matches any value for hints.

# Structs

Discriminator represents discriminators for the schema.
Hints contains the default number type to use and all the hints for enums, values and discriminators.
HintSet represents a list of paths (lists) to match for hints.
InferredNumber represents the state for a column that is a number.
InferredSchema is the schema while being inferred that holds information about fields.
Inferrer represents the `InferredSchema` with its state combined with the hints used when inferring.
Properties represents all required and optional properties which is the same as JSON objects.
Schema represents the JTD schema that will get inferred.

# Type aliases

NumType represents the type of number a number should be represented in the JTD.
SchemaType represents the type of schema element.