{"id":"json-fence-extract","version":"1.0.0","description":"List Markdown fenced code blocks (CommonMark 0.31.2) with exact spans, unwrapped content and an RFC 8259 JSON check.","supported_operations":["extract json code fences from markdown","get the json code block out of an llm reply","list fenced code blocks in a markdown document","find the ```json block in model output","pull code fences out of a block quote or list item","check whether a markdown json fence is valid json","which fenced code blocks does this markdown contain"],"unsupported_operations":["rendering Markdown to HTML or parsing inline Markdown (emphasis, links, code spans)","decoding named HTML entity references such as &ouml; in info strings (left undecoded)","finding JSON outside fenced code blocks (use json-candidate-list)","repairing invalid JSON (use json-candidate-repair)"],"semantics":["Block structure follows CommonMark 0.31.2: fenced code blocks (4.5) are found at any nesting inside block quotes (5.1) and list items (5.2); indented code (4.4), HTML blocks (4.6) and paragraphs with lazy continuation lines are honored, so a fence line inside them is not a fence. Link reference definitions (4.7) are not recognized (documented deviation, it only changes setext headings after a definition-only paragraph).","Lines end at LF, CR or CRLF; tabs use 4-column tab stops; U+0000 becomes U+FFFD. content is the code block text with container markers and up to the opening fence indentation removed, a partially used tab expanded to spaces, and every line followed by \\n.","info is the opening-fence text trimmed of spaces and tabs, with backslash escapes and decimal/hex numeric character references decoded (named entity references are kept literally). language is its first word (up to the first Unicode whitespace) or null; json_tagged is true when language, ASCII-lowercased, is json, jsonc or json5.","select (optional, default 'json_or_untagged'): 'json' returns json_tagged fences, 'json_or_untagged' also fences with no language, 'all' every fence. index counts all fences in document order from 0; fence_count is the number of all fences.","start is the UTF-16 offset of the first opening fence character; end is the UTF-16 offset of the end of the last line belonging to the block (the closing fence line, or the last line before the block was ended by its container or the document), excluding the line ending. start_line and end_line are 1-based. container_depth counts the enclosing block quotes and list items.","json_valid applies RFC 8259 section 2 strictly to content (ws value ws; only space, tab, LF, CR are whitespace; no comments, trailing commas or BOM). json_error is null when valid, else {code, offset} for the first UTF-16 offset in content where the grammar cannot continue (offset = content length with code unexpected_end)."],"limits":{"max_markdown_bytes":131072,"max_fences":512,"max_container_depth":64},"pricing":{"status":"unpriced","charge_usd":null},"input_schema":{"type":"object","additionalProperties":false,"required":["markdown"],"properties":{"markdown":{"type":"string","maxLength":131072},"select":{"type":"string","enum":["json","json_or_untagged","all"]}}},"output_schema":{"type":"object","additionalProperties":false,"required":["fences","fence_count"],"properties":{"fence_count":{"type":"integer","minimum":0,"maximum":512},"fences":{"type":"array","maxItems":512,"items":{"type":"object","additionalProperties":false,"required":["index","language","info","json_tagged","fence_char","fence_length","closed","start","end","start_line","end_line","container_depth","content","json_valid","json_error"],"properties":{"index":{"type":"integer","minimum":0},"language":{"type":["string","null"]},"info":{"type":"string"},"json_tagged":{"type":"boolean"},"fence_char":{"type":"string","enum":["`","~"]},"fence_length":{"type":"integer","minimum":3},"closed":{"type":"boolean"},"start":{"type":"integer","minimum":0},"end":{"type":"integer","minimum":0},"start_line":{"type":"integer","minimum":1},"end_line":{"type":"integer","minimum":1},"container_depth":{"type":"integer","minimum":0,"maximum":64},"content":{"type":"string"},"json_valid":{"type":"boolean"},"json_error":{"type":["object","null"],"additionalProperties":false,"required":["code","offset"],"properties":{"code":{"type":"string","enum":["unexpected_end","unexpected_character","trailing_content","invalid_escape","control_character_in_string","invalid_number","invalid_literal"]},"offset":{"type":"integer","minimum":0}}}}}}}},"examples":[{"input":{"markdown":"Here you go:\n\n```json\n{\"ok\": true}\n```\n"},"output":{"fences":[{"index":0,"language":"json","info":"json","json_tagged":true,"fence_char":"`","fence_length":3,"closed":true,"start":14,"end":38,"start_line":3,"end_line":5,"container_depth":0,"content":"{\"ok\": true}\n","json_valid":true,"json_error":null}],"fence_count":1}},{"input":{"markdown":"> ```json\n> [1, 2,]\n> ```\n","select":"all"},"output":{"fences":[{"index":0,"language":"json","info":"json","json_tagged":true,"fence_char":"`","fence_length":3,"closed":true,"start":2,"end":25,"start_line":1,"end_line":3,"container_depth":1,"content":"[1, 2,]\n","json_valid":false,"json_error":{"code":"unexpected_character","offset":6}}],"fence_count":1}}],"execute_url":"/v1/tools/json-fence-extract/versions/1.0.0/execute"}