Instream TOML to JSON encoder

Go Report Card GoDoc

TOML

A TOML parser and JSON encoder.

TOML 1.0 compliant

give it a try

Installation:

go get github.com/komkom/toml

Unmarshaling a toml doc

Since the parser transforms a toml in stream into a valid json, normal json unmarshaling from the std lib can be used.

doc := `
[some]
toml="doc"`

dec := json.NewDecoder(toml.New(bytes.NewBufferString(doc)))

st := struct {
  Some struct {
    Toml string `json:"toml"`
  } `json:"some"`
}{}

err := dec.Decode(&st)
if err != nil {
  panic(err)
}
        
fmt.Printf("toml: %v\n", st.Some.Toml)

Performance Considerations

In the repo there are two benchmarks comparing throughputs of just reading data from memory versus also transforming and parsing the data. The parser slows down data throughput around 15x here. These benchmarks are by no means thorough and only hints at an estimate.

Parser Throughput    7.05 MB/s
Memory Throughput    100.03 MB/s
Similar Resources

Golang library for reading properties from configuration files in JSON and YAML format or from environment variables.

go-config Golang library for reading properties from configuration files in JSON and YAML format or from environment variables. Usage Create config in

Aug 22, 2022

Fast JSON encoder/decoder compatible with encoding/json for Go

Fast JSON encoder/decoder compatible with encoding/json for Go

Fast JSON encoder/decoder compatible with encoding/json for Go

Jan 6, 2023

Library providing routines to merge and validate JSON, YAML and/or TOML files

Library providing routines to merge and validate JSON, YAML and/or TOML files

CONFLATE Library providing routines to merge and validate JSON, YAML, TOML files and/or structs (godoc) Typical use case: Make your application config

Sep 26, 2022

Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.

Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.

koanf (pronounced conf; a play on the Japanese Koan) is a library for reading configuration from different sources in different formats in Go applicat

Jan 8, 2023

Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.

Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.

dasel Dasel (short for data-selector) allows you to query and modify data structures using selector strings. Comparable to jq / yq, but supports JSON,

Jan 2, 2023

Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.

Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.

dasel Dasel (short for data-selector) allows you to query and modify data structures using selector strings. Comparable to jq / yq, but supports JSON,

Jan 2, 2023

converts text-formats from one to another, it is very useful if you want to re-format a json file to yaml, toml to yaml, csv to yaml, ... etc

re-txt reformates a text file from a structure to another, i.e: convert from json to yaml, toml to json, ... etc Supported Source Formats json yaml hc

Sep 23, 2022

Golang Configuration tool that support YAML, JSON, TOML, Shell Environment

Configor Golang Configuration tool that support YAML, JSON, TOML, Shell Environment (Supports Go 1.10+) Usage package main import ( "fmt" "github.c

Dec 29, 2022

Dasel - Select, put and delete data from JSON, TOML, YAML, XML and CSV files with a single tool.

Dasel - Select, put and delete data from JSON, TOML, YAML, XML and CSV files with a single tool.

Select, put and delete data from JSON, TOML, YAML, XML and CSV files with a single tool. Supports conversion between formats and can be used as a Go package.

Jan 1, 2023

Convert arbitrary formats to Go Struct (including json, toml, yaml, etc.)

go2struct Convert arbitrary formats to Go Struct (including json, toml, yaml, etc.) Installation Run the following command under your project: go get

Nov 15, 2022

Use the command to convert arbitrary formats to Go Struct (including json, toml, yaml, etc.)

go2struct-tool Use the command to convert arbitrary formats to Go Struct (including json, toml, yaml, etc.) Installation Run the following command und

Dec 16, 2021

Generic templating tool with support of JSON, YAML and TOML data

gotempl Small binary used to generate files from Go Templates and data files. The following formats are supported: JSON YAML TOML Usage usage: gotempl

Jun 15, 2022

Frep - Generate file using template from environment, arguments, json/yaml/toml config files

frep Generate file using template from environment, arguments, json/yaml/toml config files. NAME: frep - Generate file using template USAGE: fr

Nov 30, 2022

Tmpl - A tool to apply variables from cli, env, JSON/TOML/YAML files to templates

tmpl allows to apply variables from JSON/TOML/YAML files, environment variables or CLI arguments to template files using Golang text/template and functions from the Sprig project.

Nov 14, 2022

Fast and flexible JSON encoder for Go

Fast and flexible JSON encoder for Go

Jettison Jettison is a fast and flexible JSON encoder for the Go programming language, inspired by bet365/jingo, with a richer features set, aiming at

Dec 21, 2022

Fork of Go's standard library json encoder

A fork of the Go standard library's json encoder Why? https://github.com/golang/go/issues/6213 was proposed in 2013 but was never accepted. Difference

Nov 25, 2021

Go library for the TOML language

go-toml Go library for the TOML format. This library supports TOML version v1.0.0-rc.3 Features Go-toml provides the following features for using data

Dec 27, 2022

TOML parser for Golang with reflection.

THIS PROJECT IS UNMAINTAINED The last commit to this repo before writing this message occurred over two years ago. While it was never my intention to

Dec 30, 2022
Comments
  • Hexadecimal numbers are converted as strings

    Hexadecimal numbers are converted as strings

    TOML specifies that numbers starting by 0x are hexadecimal, but this package deals with them as strings. For example:

    [hextest]
    hexvalue=0x10
    decvalue=16
    

    gets rendered in JSON as

    {
       "hextest": {
          "hexvalue": "0x10",
          "decvalue": 16
       }
    }
    

    I think it should be

    {
       "hextest": {
          "hexvalue": 16,
          "decvalue": 16
       }
    }
    
  • test fails on armhf/i386: -{

    test fails on armhf/i386: -{"hex3":3735928559}, +{"hex3":-559038737}

    The test suite fails on 32-bit architectures (like armhf and i386):

        reader_test.go:184: 
            	Error Trace:	reader_test.go:184
            	Error:      	Not equal: 
            	            	expected: "{\"hex3\":3735928559}"
            	            	actual  : "{\"hex3\":-559038737}"
            	            	
            	            	Diff:
            	            	--- Expected
            	            	+++ Actual
            	            	@@ -1 +1 @@
            	            	-{"hex3":3735928559}
            	            	+{"hex3":-559038737}
            	Test:       	TestReader
    

    Bug-Debian: https://bugs.debian.org/1004048

  • TestSpecTests_invalid fails

    TestSpecTests_invalid fails

    TestSpecTests_invalid fails on Debian unstable (on every architecture):

    === RUN   TestSpecTests_invalid
    --- FAIL: TestSpecTests_invalid (0.00s)
    panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    	panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x1fd30c]
    
    goroutine 24 [running]:
    testing.tRunner.func1.2({0x22ae00, 0x3bcde0})
    	/usr/lib/go-1.18/src/testing/testing.go:1389 +0x27c
    testing.tRunner.func1()
    	/usr/lib/go-1.18/src/testing/testing.go:1392 +0x3f4
    panic({0x22ae00, 0x3bcde0})
    	/usr/lib/go-1.18/src/runtime/panic.go:838 +0x23c
    github.com/komkom/toml.TestSpecTests_invalid.func1({0x250adb, 0x18}, {0x0, 0x0}, {0x29aed0, 0x14f1698})
    	_build/src/github.com/komkom/toml/reader_test.go:300 +0x38
    path/filepath.Walk({0x250adb, 0x18}, 0x142f788)
    	/usr/lib/go-1.18/src/path/filepath/path.go:515 +0x6c
    github.com/komkom/toml.TestSpecTests_invalid(0x1482b40)
    	_build/src/github.com/komkom/toml/reader_test.go:297 +0x74
    testing.tRunner(0x1482b40, 0x25fb8c)
    	/usr/lib/go-1.18/src/testing/testing.go:1439 +0x118
    created by testing.(*T).Run
    	/usr/lib/go-1.18/src/testing/testing.go:1486 +0x3a0
    
Related tags
Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.
Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.

koanf (pronounced conf; a play on the Japanese Koan) is a library for reading configuration from different sources in different formats in Go applicat

Jan 8, 2023
Golang Configuration tool that support YAML, JSON, TOML, Shell Environment

Configor Golang Configuration tool that support YAML, JSON, TOML, Shell Environment (Supports Go 1.10+) Usage package main import ( "fmt" "github.c

Dec 29, 2022
Generic templating tool with support of JSON, YAML and TOML data

gotempl Small binary used to generate files from Go Templates and data files. The following formats are supported: JSON YAML TOML Usage usage: gotempl

Jun 15, 2022
Tmpl - A tool to apply variables from cli, env, JSON/TOML/YAML files to templates

tmpl allows to apply variables from JSON/TOML/YAML files, environment variables or CLI arguments to template files using Golang text/template and functions from the Sprig project.

Nov 14, 2022
TOML parser for Golang with reflection.

THIS PROJECT IS UNMAINTAINED The last commit to this repo before writing this message occurred over two years ago. While it was never my intention to

Jan 6, 2023
Go library for the TOML language

go-toml Go library for the TOML format. This library supports TOML version v1.0.0-rc.3 Features Go-toml provides the following features for using data

Dec 27, 2022
JSON or YAML configuration wrapper with convenient access methods.

Config Package config provides convenient access methods to configuration stored as JSON or YAML. This is a fork of the original version. This version

Dec 16, 2022
🛠 A configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP
🛠 A configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP

config A small configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP. Example func main() {

Dec 11, 2022
Type to unmarshal JSON objects while keeping the order of the keys.

orderedjson import "github.com/aybabtme/orderedjson" Sometimes you decode a JSON object in Go, and despite the JSON spec technically requiring that ke

Oct 29, 2022