---
title: "@std/cbor"
description: "Utilities for parsing and serializing Concise Binary Object Representation (CBOR)"
jsr: jsr:@std/cbor
pkg: cbor
version: 0.1.9
generated: true
stability: unstable
---
<!-- Autogenerated from JSR docs. Do not edit directly. -->

:::info Unstable

This @std package is experimental and its API may change without a major version bump.

:::
## Overview

<p>Concise Binary Object Representation (CBOR) is a binary data serialization
format optimized for compactness and efficiency. It is designed to encode a
wide range of data types, including integers, strings, arrays, and maps, in a
space-efficient manner.
<a href="https://datatracker.ietf.org/doc/html/rfc8949" rel="nofollow">RFC 8949 - Concise Binary Object Representation (CBOR)</a>
spec.</p>
<h3 id="limitations">
Limitations</h3>
<ul>
<li>This implementation only supports the encoding and decoding of
"Text String" keys.</li>
<li>This implementation encodes decimal numbers with 64 bits. It takes no
effort to figure out if the decimal can be encoded with 32 or 16 bits.</li>
<li>When decoding, integers with a value below 2 ** 32 will be of type
<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number" rel="nofollow">number</a>, with all larger integers being of type <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/BigInt" rel="nofollow">bigint</a>.</li>
</ul>
<p>Functions and classes may have more specific limitations listed.</p>

```js
import { assert, assertEquals } from "@std/assert";
import { decodeCbor, encodeCbor } from "@std/cbor";

const rawMessage = "I am a raw Message!";

const encodedMessage = encodeCbor(rawMessage);
const decodedMessage = decodeCbor(encodedMessage);

assert(typeof decodedMessage === "string");
assertEquals(decodedMessage, rawMessage);
```

### Add to your project

```sh
deno add jsr:@std/cbor
```

<a href="https://jsr.io/@std/cbor/doc" class="docs-cta jsr-cta">See all symbols in @std/cbor on
<svg class="inline ml-1" viewBox="0 0 13 7" aria-hidden="true" height="20"><path d="M0,2h2v-2h7v1h4v4h-2v2h-7v-1h-4" fill="#083344"></path><g fill="#f7df1e"><path d="M1,3h1v1h1v-3h1v4h-3"></path><path d="M5,1h3v1h-2v1h2v3h-3v-1h2v-1h-2"></path><path d="M9,2h3v2h-1v-1h-1v3h-1"></path></g></svg></a>

<!-- custom:start -->
<!-- Add persistent custom content below. This section is preserved across generations. -->

<!-- custom:end -->
