﻿# Protobuf Duration has a seconds-string JSON contract

Protobuf Duration encodes seconds and nanoseconds internally but uses a seconds string in JSON; its unit, sign and meaning differ from a timestamp and from arbitrary integer delays.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/guide-protobuf-duration-json-seconds/
Language: en

## Identify the duration before converting its representation

A service returns an extraction elapsed time and accepts a delay before its next observation. The [well-known Duration type](https://protobuf.dev/reference/protobuf/google.protobuf/) represents a signed fixed span independent of calendars. Its message fields hold seconds and fractional nanoseconds. Do not infer milliseconds from an integer merely because another nearby API used them, and do not treat a fixed duration as a calendar month or a local-clock recurrence.

## Follow the custom JSON representation

The [ProtoJSON specification](https://protobuf.dev/programming-guides/json/) represents Duration as a string ending in `s`, such as `"1.5s"`. It does not serialize the ordinary message-shaped seconds and nanos object as the canonical JSON value. Generated output has specified fractional precision, and accepted fractions must fit nanosecond precision with the suffix present. A general JSON serializer applied to an internal object can therefore produce valid JSON that violates this interface's Duration representation.

## Preserve the sign relationship

The type reference defines consistency between seconds and the fractional field for spans whose whole-second part is nonzero. Subsecond negative spans have their own valid representation. Use the type's codec and normalization rules rather than independently attaching a sign to each component. Otherwise equivalent-looking arithmetic can construct an invalid message or change the intended delay when the application crosses between internal fields and external seconds strings.

## Distinguish a span from an absolute point

[API time guidance](https://google.aip.dev/142) recommends different types for durations and timestamps even though their internal field shapes look similar. The same numeric components cannot be relabeled without changing meaning. For an offset within a document's audio or video stream, also declare the reference point. A duration says how far from that origin; it does not by itself identify which recording or timeline the value addresses.

## Review the consumer's units and origin

Inspect the received JSON value, parsed duration and final operation that consumes it. [Task budgets](/journal/learn-codex-task-budgets/) distinguish an elapsed measurement from an execution allowance; [tool observations](/journal/learn-codex-tool-observation/) preserve the conversion. The accepted result should retain the same span and intended reference, rather than merely produce a plausible number. This makes a Duration field usable across languages without relying on undocumented seconds-versus-milliseconds assumptions or accidental similarity to a timestamp object.
