Nestext
Processing NestedText
Install / Use
/learn @npillmayer/NestextREADME
nestext
Processing NestedText (NestedText: A Human Friendly Data Format) in Go.
A description of NestedText by the authors:
NestedText is a file format for holding structured data that is to be entered, edited, or viewed by people. It allows data to be organized into a nested collection of dictionaries, lists, and strings without the need for quoting or escaping. In this way it is similar to JSON, YAML and TOML, but without the complexity and risk of YAML and without the syntactic clutter of JSON and TOML. NestedText is both simple and natural.
To get a feel for the NestedText format, take a look at the following example (shortended version from the NestedText site):
# Contact information for our officers
president:
name: Katheryn McDaniel
address:
> 138 Almond Street
> Topeka, Kansas 20697
phone:
cell: 1-210-555-5297
home: 1-210-555-8470
# Katheryn prefers that we always call her on her cell phone.
email: KateMcD@aol.com
additional roles:
- board member
vice president:
name: Margaret Hodge
…
NestedText does not interpret any data types (unlike YAML), nor does it impose a schema. All of that has to be done by the application.
Decoding
Parse(…) is the top-level API:
input := `
# Example for a NestedText dict
a: Hello
b: World
`
result, err := nestext.Parse(strings.NewReader(input))
if err != nil {
log.Fatal("parsing failed")
}
fmt.Printf("result = %#v\n", result)
will yield:
result = map[string]interface {}{"a":"Hello", "b":"World"}
Clients may use tools like mitchellh/mapstructure or knadh/koanf for further processing.
Encoding
Sub-package ntenc provides an encoder-API:
var config = map[string]interface{}{
"timeout": 20,
"ports": []interface{}{6483, 8020, 9332},
}
n, err := ntenc.Encode(config, os.Stdout)
fmt.Println("------------------------------")
fmt.Printf("%d bytes written, error: %v", n, err != nil)
will yield:
ports:
- 6483
- 8020
- 9332
timeout: 20
------------------------------
46 bytes written, error: false
Status
Tested with NestedText test suite for Version 3.1.0.
Related Skills
node-connect
344.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
99.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
344.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
