liveBook · Manning

JSONL

As explained in Data Storytelling with Altair and AI

JSONL is a line-oriented text format in which each line contains a separate JSON value, commonly an object.

JSONL stores independent JSON records one per line. For fine-tuning chat models, each record can hold a messages array that defines a system instruction, user prompt, and assistant completion. section 7.4.1

A chat-training record

A record can instruct a data analyst to address the general public, provide household-chore percentages as the user input, and supply a plain-language commentary as the assistant output. section 7.4.1

Listing 7.1 The structure of a JSONL file
{
  "messages": [
     {
    "role": "system",
  "content": "You are a data analyst showing data to the general public."
     },
     {
         "role": "user",
         "content": "Distribution of household chores 
                                  (Cooking 35% Cleaning 30% Laundry 20%, Yard work 15%)"
     },
     {
          "role": "assistant",
           "content": "Cooking takes up the largest portion at 35%. 
                      Cleaning follows at 30% while laundry 
                      and yard work accounts for 20% and 15% respectively."

     }
  ]
}

Inspect the message roles and fields used in a JSONL training record. section 7.4.1

To create the file from CSV data, load prompt and completion columns into a pandas DataFrame, build one messages object per row, then write each object with json.dump followed by a newline. section 7.4.1

Listing 7.2 How to convert the CSV file into JSONL
import pandas as pd
import json

df = pd.read_csv('general-public.csv')

json_list = []

for index, row in df.iterrows():
    json_object = {
        "messages": [
            {
                "role": "system",
                "content": "You are a data analyst showing data to the general public."
            },
            {
                "role": "user",
                "content": row['prompt']
            },
            {
                "role": "assistant",
                "content": row['completion']
            }
        ]
    }
    json_list.append(json_object)

with open('general-public.jsonl', 'w') as outfile:
    for json_object in json_list:
        json.dump(json_object, outfile)
        outfile.write('\n')

Follow the Python loop that converts each CSV row into a newline-delimited JSON object. section 7.4.1

How Data Storytelling with Altair and AI covers it

How deep it goes
Shows the messages schema and a pandas-based CSV conversion script, without detailing JSONL syntax beyond the training structure.
Examples
Uses household chores, data-commentary prompts, and CSV rows converted into messages records.
What it assumes
Assumes a CSV dataset and pandas DataFrame, then demonstrates the conversion procedure from those inputs.
What you can do after
Apply it via Python and the OpenAI API to prepare and upload a fine-tuning dataset.
How it connects
Connects JSONL to fine-tuning, chat messages, pandas DataFrames, CSV files, and the OpenAI API.

Also explained in

Compare how 3 books explain JSONL →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Storytelling with Altair and AI. The section links point to the parts of the book it draws on.