fmd2json

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

fmd2json

Test Status Coverage Status MIT License PkgGoDev

fmd2json short description

Synopsis

Convert Markdown files with YAML frontmatter to JSON.

% cat article.md
---
title: Hello
tags:
  - go
  - cli
---
This is the body.

% fmd2json article.md
{"title":"Hello","tags":["go","cli"],"filename":"article","body":"This is the body.\n","mtime":"2025-01-01T00:00:00+09:00"}

Description

fmd2json reads Markdown files with YAML frontmatter and outputs JSON. Frontmatter properties are included as-is, along with default properties:

  • dir — directory path of the input file (omitted when empty or current directory, always uses / as separator)
  • filename — file name without .md extension
  • body — content after frontmatter (or entire content if no frontmatter)
  • mtime — file modification time in RFC 3339 format

Multiple files produce newline-delimited JSON (ndjson):

% fmd2json docs/a.md docs/b.md
{"dir":"docs","filename":"a",...}
{"dir":"docs","filename":"b",...}

Read from stdin with -:

% cat article.md | fmd2json -
{"filename":"","body":"...","..."}

Use -filename to specify the filename when reading from stdin:

% cat article.md | fmd2json -filename article.md -
{"filename":"article","body":"...","..."}

Read a file list from stdin (when no arguments given):

% find . -name '*.md' | fmd2json
{"dir":"./docs","filename":"article1",...}
{"dir":"./docs","filename":"article2",...}
--jq option

Filter and transform JSON output using jq expressions (powered by gojq):

% fmd2json --jq '.filename' a.md b.md
"a"
"b"

% fmd2json --jq '{title: .filename, size: (.body | length)}' article.md
{"title":"article","size":42}

By default, string values are output as JSON-encoded strings (with quotes and escapes), which keeps each result on a single line even if the value contains newlines. This is safe for multi-file processing:

% fmd2json --jq '.body' a.md b.md
"first line\nsecond line\n"
"another body\n"

Use --raw-output (or -r) to output raw strings without JSON encoding, similar to jq -r:

% fmd2json --jq '.filename' -r a.md b.md
a
b

Installation

# Install the latest version. (Install it into ./bin/ by default).
% curl -sfL https://raw.githubusercontent.com/Songmu/fmd2json/main/install.sh | sh -s

# Specify installation directory ($(go env GOPATH)/bin/) and version.
% curl -sfL https://raw.githubusercontent.com/Songmu/fmd2json/main/install.sh | sh -s -- -b $(go env GOPATH)/bin [vX.Y.Z]

# In alpine linux (as it does not come with curl by default)
% wget -O - -q https://raw.githubusercontent.com/Songmu/fmd2json/main/install.sh | sh -s [vX.Y.Z]

# go install
% go install github.com/Songmu/fmd2json/cmd/fmd2json@latest

Author

Songmu

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, argv []string, outStream, errStream io.Writer) error

Run the fmd2json

Types

This section is empty.

Directories

Path Synopsis
cmd
fmd2json command

Jump to

Keyboard shortcuts

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