# Decoding tools

Use our [DCS decoder](https://dcs-decoder.didomi.io/) to quickly and easily decode your Didomi Consent Strings and view their contents in a human-readable format.

### SDK API - Web

The Didomi Web SDK provides a JavaScript API to decode the Didomi Consent String (DCS). This API can be used in two ways depending on your needs:

#### Simple decoding

This method allows you to decode a DCS string into a readable JSON object containing the user’s consent preferences, timestamps, and vendor/purpose consents.

Use this if you’re only interested in accessing and inspecting user consent choices (e.g. for debugging or integration validation).

Query example

```javascript
const factory = Didomi.getCedFactory()
undefined
dcs = "dcs_token_with signature".split('.')[0]
'dcs_token_without_signature'
factory.decode(dcs)
```

Response example

```json
{
  "user_id": "19710e89-951e-6842-8355-d094b60e4924",
  "created": "2025-05-27T08:42:48.500Z",
  "updated": "2025-05-27T08:42:51.000Z",
  "purposes_optin": {
    "enabled": [
      3,
      5,
      8,
      9,
      10,
      16,
      80
    ],
    "disabled": []
  },
  "purposes_optout": {
    "enabled": [],
    "disabled": []
  },
  "vendors_optin": {
    "enabled": [
      2,
      3,
      1010
    ],
    "disabled": []
  },
  "vendors_optout": {
    "enabled": [
      2
    ],
    "disabled": []
  }
}
```

#### Granular decoding

This advanced method provides insight into the internal structure of the DCS, including the encoding strategy used for each field and its offset in the binary string. This is useful for debugging, validation, or developing your own decoder.

Query example

```javascript
const entries = [];
undefined
const logs = { enabled: true, entries };

undefined
factory.decode(dcs, {logs})
{user_id: '19710e89-951e-6842-8355-d094b60e4924', created: '2025-05-27T08:42:48.500Z', updated: '2025-05-27T08:42:51.000Z', purposes_optin: {…}, purposes_optout: {…}, …}
entries
```

Response example

```json
[
    {
        "key": "version",
        "offset": 0,
        "usedEncoder": "u6"
    },
    {
        "key": "user_id",
        "offset": 6,
        "usedEncoder": "UUID"
    },
    {
        "key": "created",
        "offset": 134,
        "usedEncoder": "date"
    },
    {
        "key": "updated",
        "offset": 170,
        "usedEncoder": "date"
    },
    {
        "key": "sync",
        "offset": 206
    },
    {
        "key": "purposes_optin",
        "offset": 207,
        "usedEncoder": "bitField2Bits"
    },
    {
        "key": "purposes_optout",
        "offset": 386,
        "usedEncoder": "bitField2Bits"
    },
    {
        "key": "vendors_optin",
        "offset": 405,
        "usedEncoder": "rangesFibonacci"
    },
    {
        "key": "vendors_optout",
        "offset": 451,
        "usedEncoder": "bitField2Bits"
    }
]
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.didomi.io/cmp/didomi-consent-string/decoding-tools.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
