npm i grf-format
View on GitHub
What is GRF?
GuinRank Record Format (GRF) is a lightweight, line-oriented text format designed specifically to solve the frequent breakdown of standard data formats (JSON, CSV, and Markdown) when generated by Small Language Models (SLMs) and generative AI engines.
It is utilized throughout GuinRank AI tools (including Topic Angles, Ask Radar, and Hook Generator) to stream structured data from generative AI models directly into clean application objects with zero parsing failures.
Why GRF? (Comparison Table)
| Challenge / Issue | In JSON | In CSV | In GRF (GuinRank Record Format) |
|---|---|---|---|
| Quote & Bracket Escaping | Strictly required; small models fail easily | Not required, but commas collide with text | Not required — No quotes or brackets needed |
| Common Text Delimiters | " and {} |
, (frequent in natural text) |
¦ (Broken bar - extremely rare in prose) |
| Positional Dependence | No (explicit object keys) | Yes (a missing cell corrupts all columns) | No (every line has an explicit key name) |
| Multi-line Prose Handling | Complex (requires \n escaping) |
Complex (requires quoted multi-line wrapping) | Single line constraint — Simple and safe |
| Missing / Extra Orphan Lines | Fatal SyntaxError; breaks the whole JSON | Column shifting & misalignment | Self-healing — Orphan lines append automatically |
Specification Architecture
A GRF document consists of one or more records. Each record begins with a marker line and contains key-value fields and optional tabular data.
~RECORD
text_h1: Product Title
text_h2: Short summary description
reason: The reason here, even with a normal comma, will never break parsing!
table_fields: name¦price¦stock
table_row: Pen¦10¦50
table_row: Notebook¦5¦200
~RECORD
text_h1: Second Product
table_fields: name¦price
table_row: Book¦20
1. Regular Fields (Key: Value)
- The separator between key and value is the first colon (
:) on the line only (non-greedy split). - The field key must be a single word without spaces (e.g.
text_h1,reason,angle_type). - If the part before the colon contains spaces (e.g.
Date: 2026-09-03), it is not treated as a new field, but safely treated as natural text (an orphan line) belonging to the previous field. - Values must reside on a single continuous line. Any commas, quotes, or extra colons in the value are 100% safe.
2. Tabular Data (table_fields & table_row)
table_fields: col1¦col2¦col3— Defines the column names separated by the broken bar (¦).table_row: val1¦val2¦val3— Can repeat for any number of rows in the same column order.- The official column separator is the broken bar (
¦, UnicodeU+00A6), which is practically nonexistent in standard human prose.
3. Self-Healing Orphan Lines
If an AI model hallucinatingly outputs an unkeyed line, wraps text mid-sentence, or outputs an explanation line without a valid key:, GRF does not crash.
Instead, the parser automatically appends the rogue line to the preceding field's value separated by a space, logs a console warning, and continues processing without interruption.
Interactive GRF Playground & Converter
Test live parsing and bidirectional conversion between GRF, JSON, and CSV in real time using the grf-parser engine.
Installation & Quick Start
The GRF parser has zero external dependencies and weighs less than 4KB minified. You can install it via NPM or embed it directly in HTML:
npm install grf-format
<script src="/script/grf-parser.min.js"></script>
<script>
const json = window.GRF.grfToJson(grfText);
</script>
JavaScript API Reference
| Function | Direction | Description |
|---|---|---|
parseCustomFormat(grfText) |
GRF ➔ Raw JS Object |
Parses text into an array of records: { fields: {}, table: { fields: [], rows: [] } }. |
toJSON(records, pretty = true) |
Records ➔ JSON string |
Converts raw parsed records into a clean JSON string, turning table rows into keyed objects. |
grfToJson(grfText, pretty = true) |
GRF ➔ JSON string |
One-step conversion from raw GRF text straight to a ready-to-use JSON string. |
jsonToGrf(jsonInput) |
JSON ➔ GRF string |
Converts a JSON string or array of objects back into standard GRF text. |
grfToCsv(grfText) |
GRF ➔ CSV string |
Flattens records into denormalized CSV rows, repeating regular fields for each table row. |
csvToGrf(csvText) |
CSV ➔ GRF string |
Reconstructs GRF records from a flattened CSV document. |
const { grfToJson, jsonToGrf, grfToCsv } = require('grf-format');
const grfData = `
~RECORD
title: GuinRank SEO Analyzer
score: 98
table_fields: keyword¦volume¦cpc
table_row: ai writing¦12000¦1.85
table_row: seo tools¦45000¦3.20
`;
// 1. Convert to JSON
const jsonOutput = grfToJson(grfData);
console.log(jsonOutput);
// 2. Convert to CSV
const csvOutput = grfToCsv(grfData);
console.log(csvOutput);
AI Model System Prompt (Copy & Paste)
Instruct your AI models (Claude, GPT, Gemini, Mistral, Ollama) to strictly output in GRF format by appending this instruction to your system prompt:
You must format your entire response in GRF (GuinRank Record Format) with no markdown fences, no json brackets, and no quotes.
Rules:
1. Every record begins with: ~RECORD
2. Single-line fields use: field_name: value (field_name must be a single word without spaces).
3. If tabular data is needed, use:
table_fields: col1¦col2¦col3
table_row: val1¦val2¦val3
(Column delimiter is strictly the broken bar symbol '¦').
4. Do not wrap values in quotes. Keep each field value on a single line.