---
title: "@std/front-matter"
description: "Extract front matter from strings"
jsr: jsr:@std/front-matter
pkg: front-matter
version: 1.0.9
generated: true
stability: stable
---
<!-- Autogenerated from JSR docs. Do not edit directly. -->

## Overview

<p>Extracts
<a href="https://daily-dev-tips.com/posts/what-exactly-is-frontmatter/" rel="nofollow">front matter</a>
from strings. Adapted from
<a href="https://github.com/jxson/front-matter/blob/36f139ef797bd9e5196a9ede03ef481d7fbca18e/index.js" rel="nofollow">jxson/front-matter</a>.</p>
<h2 id="supported-formats">
Supported formats</h2>
<h3 id="json">
JSON</h3>

```js
import { test, extractJson } from "@std/front-matter";
import { assertEquals } from "@std/assert";

const str = "---json\n{\"and\": \"this\"}\n---\ndeno is awesome";

assertEquals(test(str), true);
assertEquals(extractJson(str), {
  frontMatter: "{\"and\": \"this\"}",
  body: "deno is awesome",
  attrs: { and: "this" }
});
```

<p><a href="https://jsr.io/@std/front-matter@1.0.9/doc/~/extractJson" rel="nofollow"><code>extract</code></a> and <a href="https://jsr.io/@std/front-matter@1.0.9/doc/~/test" rel="nofollow"><code>test</code></a> support the following
delimiters.</p>

```js
---json
{
  "and": "this"
}
---
```

```js
{
  "is": "JSON"
}
```

<h3 id="toml">
TOML</h3>

```js
import { test, extractToml } from "@std/front-matter";
import { assertEquals } from "@std/assert";

const str = "---toml\nmodule = 'front_matter'\n---\ndeno is awesome";

assertEquals(test(str), true);
assertEquals(extractToml(str), {
  frontMatter: "module = 'front_matter'",
  body: "deno is awesome",
  attrs: { module: "front_matter" }
});
```

<p><a href="https://jsr.io/@std/front-matter@1.0.9/doc/~/extractToml" rel="nofollow"><code>extract</code></a> and <a href="https://jsr.io/@std/front-matter@1.0.9/doc/~/test" rel="nofollow"><code>test</code></a> support the following
delimiters.</p>

```js
---toml
this = 'is'
---
```

```js
= toml =
parsed = 'as'
toml = 'data'
= toml =
```

```js
+++
is = 'that'
not = 'cool?'
+++
```

<h3 id="yaml">
YAML</h3>

```js
import { test, extractYaml } from "@std/front-matter";
import { assertEquals } from "@std/assert";

const str = "---yaml\nmodule: front_matter\n---\ndeno is awesome";

assertEquals(test(str), true);
assertEquals(extractYaml(str), {
  frontMatter: "module: front_matter",
  body: "deno is awesome",
  attrs: { module: "front_matter" }
});
```

<p><a href="https://jsr.io/@std/front-matter@1.0.9/doc/~/extractYaml" rel="nofollow"><code>extract</code></a> and <a href="https://jsr.io/@std/front-matter@1.0.9/doc/~/test" rel="nofollow"><code>test</code></a> support the following
delimiters.</p>

```js
---
these: are
---
```

```js
---yaml
all: recognized
---
```

```js
= yaml =
as: yaml
= yaml =
```

### Add to your project

```sh
deno add jsr:@std/front-matter
```

<a href="https://jsr.io/@std/front-matter/doc" class="docs-cta jsr-cta">See all symbols in @std/front-matter on
<svg class="inline ml-1" viewBox="0 0 13 7" aria-hidden="true" height="20"><path d="M0,2h2v-2h7v1h4v4h-2v2h-7v-1h-4" fill="#083344"></path><g fill="#f7df1e"><path d="M1,3h1v1h1v-3h1v4h-3"></path><path d="M5,1h3v1h-2v1h2v3h-3v-1h2v-1h-2"></path><path d="M9,2h3v2h-1v-1h-1v3h-1"></path></g></svg></a>

<!-- custom:start -->
<!-- Add persistent custom content below. This section is preserved across generations. -->

<!-- custom:end -->
