// 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 Extract JSON front matter
 * ```ts
 * import { extract } from "@std/front-matter/json";
 * import { assertEquals } from "@std/assert";
 *
 * const output = `---json
 * {
 *   "title": "Three dashes marks the spot"
 * }
 * ---
 * Hello, world!`;
 * const result = extract(output);
 *
 * assertEquals(result, {
 *   frontMatter: '{\n  "title": "Three dashes marks the spot"\n}',
 *   body: "Hello, world!",
 *   attrs: { title: "Three dashes marks the spot" },
 * });
 * ```
 */
export const extract: Extractor = createExtractor({
  json: JSON.parse as Parser,
});

// denoCacheMetadata={"headers":{"vary":"Origin","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","alt-svc":"h3=\":443\"; ma=86400","date":"Tue, 28 Jul 2026 12:31:15 GMT","x-content-type-options":"nosniff","x-jsr-backend":"modules","content-length":"859","cross-origin-resource-policy":"cross-origin","server":"cloudflare","access-control-expose-headers":"*","content-type":"text/typescript","etag":"\"755673b294633d15eea969163d733a80\"","x-robots-tag":"noindex","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=FTZib9%2FH6oqlEehZnYyVy3uZqa7CPIFDeECHA2KD47urCzUini2J1UZsAFKV%2B1z0KSb25G%2BAAWrI9eJaFNYu514OIwKzW194KtfI0LiDyira2eJvsqH8cNU%3D\"}]}","cf-ray":"a223e656afba7db6-LAX","access-control-allow-origin":"*","set-cookie":"__cf_bm=hWgg5Nw434CCG9.zLEcWN1VgoJdayRC3.1mhZLF3RHM-1785241874.9925864-1.0.1.1-dlMXXVlMV0JoqHwxJ4CMKI64.L6nwm0v2vU_hAVegItucYpi_grue2OvcdVQcY9QJx_fMnpQ5tM6WINvI8.1fL2FSGgl6q_9uGM11MDaZ12uwoLizowwRDjkao5l4CDo; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","cache-control":"public, max-age=31536000, immutable","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';"},"url":"https://jsr.io/@std/front-matter/0.224.3/json.ts","time":1785241875}