Skip to main content
Module

std/front_matter/json.ts

The Deno Standard Library
Latest
File
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { createExtractor, type Extractor, type Parser,} from "./create_extractor.ts";
/** * Extracts and parses {@link https://www.json.org/ | JSON } from the metadata * of front matter content. * * @example * ```ts * import { extract } from "https://deno.land/std@$STD_VERSION/front_matter/json.ts"; * * const output = `---json * { * "title": "Three dashes marks the spot" * } * --- * Hello, world!`; * const result = extract(output); * * result.frontMatter; // '{\n "title": "Three dashes marks the spot"\n}' * result.body; // "Hello, world!" * result.attrs; // { title: "Three dashes marks the spot" } * ``` */export const extract: Extractor = createExtractor({ json: JSON.parse as Parser,});