jsonyaml

package module
v0.0.0-...-b62ae7e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package jsonyaml provides a MetaLoader that accepts either YAML or JSON frontmatter.

YAML frontmatter is delimited by ---\n ... \n---\n:

---
title: My Post
tags: [go, web]
---
body content here

JSON frontmatter is a JSON object terminated by a closing }\n on its own line:

{
"title": "My Post",
"tags": ["go", "web"]
}
body content here

YAML is parsed via yamlite (no heavy YAML library dependency).

Index

Constants

This section is empty.

Variables

View Source
var Loader = func(raw []byte) (map[string]any, []byte, error) {
	if bytes.HasPrefix(raw, []byte("---\n")) {
		return loadYAML(raw)
	}
	if bytes.HasPrefix(raw, []byte("{\n")) {
		return loadJSON(raw)
	}
	return map[string]any{}, raw, nil
}

Loader parses YAML or JSON frontmatter and returns the metadata and body. Files with no recognized frontmatter prefix are returned as body-only with empty metadata.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL