Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

JSON

JSON is a text format of objects, arrays, and values used for APIs, annotations, and model outputs. Syntax rules, ML uses, JSON Lines, and code.

JSON, short for JavaScript Object Notation, is a lightweight, text-based format for storing and exchanging structured data. Douglas Crockford specified it in the early 2000s, basing it on JavaScript's object literal syntax, and it is now standardized as IETF RFC 8259 and ECMA-404. JSON is language-independent, readable by people, and parsed by the standard library of almost every programming language, which makes it the default format for web APIs. In machine learning (ML), it carries predictions out of inference engines, stores dataset annotations, logs experiment metadata, and defines the structured outputs of large language models (LLMs).

JSON Syntax#

A JSON document is built from two containers and four kinds of values:

  • Objects: Unordered sets of key-value pairs in braces, such as {"name": "bus", "confidence": 0.94}. Keys must be strings in double quotes.
  • Arrays: Ordered lists in brackets, such as [48.5, 398.0, 245.3, 902.1].
  • Values: Strings, numbers, the literals true, false, and null, or nested objects and arrays.

The format is strict. Comments, trailing commas, single-quoted strings, and the values NaN and Infinity are not allowed, although Python's json module writes NaN by default unless allow_nan=False is set, producing files that strict parsers reject. RFC 8259 also warns that numbers are only reliably exchanged within IEEE 754 double precision, so integers larger than 2⁵³ − 1, such as some database ids, are often sent as strings.

JSON in Machine Learning Workflows#

When a camera in a security system sends a frame to an object detection service, the model serving layer typically answers with JSON: one record per detected object with its class, confidence score, and bounding box coordinates, ready for dashboards, mobile apps, and document databases such as MongoDB.

Annotation formats rely on JSON as well. The COCO dataset stores all labels for a split in one JSON file with three main lists: images with file names and sizes, categories with class ids and names, and annotations, where each entry points to an image and a category by id and stores a box as [x, y, width, height] in pixels from the top-left corner. The YOLO format instead uses one text file per image with normalized center coordinates, and converting between the two is a routine step in data annotation pipelines, although a custom dataset class can also train YOLO on COCO JSON directly.

JSON Lines, also called NDJSON, puts one complete JSON object on each line. Files can then be appended to, streamed, and split without parsing the whole document, which suits training logs, prediction streams, and the instruction datasets used to fine-tune LLMs. For LLMs, JSON Schema describes the exact fields an application expects, and structured outputs and function calling constrain a model to produce JSON that matches it. GeoJSON, standardized as RFC 7946, applies the format to geographic features, which lets satellite image analysis place detections on a map.

Converting Predictions to JSON#

Ultralytics YOLO Results objects serialize their predictions with to_json(), writing one record per detection with the class name, class id, confidence, and box corners x1, y1, x2, y2, plus mask or keypoint coordinates for instance segmentation and pose estimation models. The following example runs YOLO26 on a sample image and parses the JSON back with Python's standard library:

import json

from ultralytics import YOLO

# Load a pretrained YOLO26 detection model and run inference
model = YOLO("yolo26n.pt")
results = model("https://ultralytics.com/images/bus.jpg")
result = results[0]

# Serialize every detection to a JSON string (normalize=True would scale boxes to 0-1)
json_string = result.to_json()

# Any JSON parser can read it back, here into a list of Python dicts
detections = json.loads(json_string)
print(json.dumps(detections[0], indent=2))

The printed record is a JSON object with name, class, and confidence keys and a nested box object holding the corner coordinates in pixels.

  • YAML: A more readable format that allows comments and indentation-based nesting, common for training configurations and dataset definitions. YAML 1.2 is designed as a superset of JSON, so most JSON documents are valid YAML.
  • XML: A tag-based format, used for Pascal VOC annotations, that is more verbose than JSON and supports attributes, namespaces, and schemas.
  • CSV: A flat table format that is compact for tabular data but cannot nest objects or lists.
  • Binary formats: Protocol Buffers and MessagePack are smaller and faster to parse than JSON but not human-readable. ONNX model files are stored as Protocol Buffers messages.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Turn drone and aerial imagery into real-time insights for agriculture, aquaculture, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning