Skip to main content

Message schemas

Foxglove often requires incoming messages to conform to specific structures to visualize them properly. Using Foxglove schemas helps you take full advantage of the platform's built-in visualizations.

Built-in support

The SDK allows you to log messages adhering to Foxglove schemas without worrying about the underlying serialization. See Logging messages with Foxglove schemas for an example.

Other supported formats

If you've already written custom messages, you can transform them into Foxglove-supported schemas using a message converter extension.

Protobuf and JSON Schema

Copy the .proto files or .json files you need directly into your project, and use them to start publishing data to the app or an MCAP file.

NOTE: For Protobuf data, time values of type google.protobuf.Timestamp or google.protobuf.Duration will appear with sec and nsec fields (instead of seconds and nanos) in user scripts, message converters, and the rest of Foxglove, for consistency with time and duration types in other data formats.

Schemaless JSON

MCAP supports writing JSON messages without specifying a schema. To write JSON message data with no schema, set your channel's message encoding to json and the schema ID to 0. This indicates there is no schema for the channel: https://mcap.dev/spec#channel-op0x04

ROS

Install the foxglove_msgs package:

sudo apt install ros-noetic-foxglove-msgs # For ROS 1
sudo apt install ros-galactic-foxglove-msgs # For ROS 2

Then, import the schemas you need inside your ROS project to start publishing data:

from foxglove_msgs.msg import Vector2


msg = Vector2()
msg.x = 0.5
msg.y = 0.7

TypeScript

Import Foxglove schemas as TypeScript types for type-checking purposes.

In Foxglove's User Scripts panel, you can specify the schema you want with Message<"foxglove.[SchemaName]">:

import { Input, Message } from "./types";

type Output = Message<"foxglove.Point2">;

export const inputs = ["/input/topic"];
export const output = "/studio_script/output_topic";

export default function script(event: Input<"/input/topic">): Output {
return { x: 1, y: 2 };
}

Note that if you're working with the MCAP TypeScript SDK, you can import JSON schemas via the @foxglove/schemas npm package:

import { Point2 } from "@foxglove/schemas";

const myImage: Point2 = { x: 1, y: 2 };