{"record":{"id":"89994b4f53d835e1","repo":"hashicorp/vault","slug":"vault-expects-data-to-be-formatted-as-an-json-obje","errorCode":null,"errorMessage":"Vault expects data to be formatted as an JSON object.","messagePattern":"Vault expects data to be formatted as an JSON object\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ui/app/lib/kv-object.js","lineNumber":13,"sourceCode":"/**\n * Copyright IBM Corp. 2016, 2025\n * SPDX-License-Identifier: BUSL-1.1\n */\n\nimport ArrayProxy from '@ember/array/proxy';\nimport { typeOf } from '@ember/utils';\nimport { guidFor } from '@ember/object/internals';\n\nexport default ArrayProxy.extend({\n  fromJSON(json) {\n    if (json && typeOf(json) !== 'object') {\n      throw new Error('Vault expects data to be formatted as an JSON object.');\n    }\n    const contents = Object.keys(json || []).map((key) => {\n      const obj = {\n        name: key,\n        value: json[key],\n      };\n      guidFor(obj);\n      return obj;\n    });\n    this.setObjects(\n      contents.sort((a, b) => {\n        if (a.name === '') {\n          return 1;\n        }\n        if (b.name === '') {\n          return -1;\n        }\n        return a.name.localeCompare(b.name);","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/hashicorp/vault/blob/744b611b5700b3b7f82d76b4d6938a91b9989367/ui/app/lib/kv-object.js#L1-L31","documentation":"Thrown by the KV secret editing utility (ui/app/lib/kv-object.js:13). fromJSON() converts a KV secret's data payload into an array of {name, value} row objects for the editor UI. Vault KV secrets must be a JSON object (a map of string keys to values); if the supplied json is an array, string, number, or other non-object type, the guard throws before mapping.","triggerScenarios":"Loading or rendering a KV secret (v1 or v2) whose data field is not a plain object — e.g. written via the raw HTTP API as a top-level JSON array or scalar — or calling KvObject.fromJSON directly with such a payload.","commonSituations":"Secrets written by scripts or API integrations that serialize a list or bare value instead of a key/value map; migrating tools that emit JSON arrays; malformed JSON produced upstream that parses to a non-object.","solutions":["Rewrite the secret so its data is a JSON object of key/value pairs (vault kv put secret/foo mykey=myvalue)","If a list is genuinely needed, store it as the value of a key (e.g. {\"items\": \"a,b,c\"} or a JSON-stringified array)"],"exampleFix":"// before: top-level array breaks the editor\nawait fetch('/v1/secret/data/app', { method: 'POST', body: JSON.stringify({ data: ['a', 'b'] }) });\n\n// after: data must be a key/value object\nawait fetch('/v1/secret/data/app', { method: 'POST', body: JSON.stringify({ data: { items: 'a,b' } }) });","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"import { typeOf } from '@ember/utils';\n// Mirrors the library's own check: typeOf returns 'object' only for plain objects,\n// 'array' for arrays, 'string'/'number'/etc. otherwise\nfunction isKvDataObject(json: unknown): json is Record<string, unknown> {\n  return !!json && typeOf(json) === 'object';\n}\n\nif (!isKvDataObject(secretData)) {\n  throw new Error('KV secret data must be a JSON object of key/value pairs');\n}","tryCatchPattern":"try {\n  kvObject.fromJSON(data);\n} catch (e) {\n  if (e.message.includes('formatted as an JSON object')) {\n    notifyUser('This secret is not a key/value object — rewrite it as {\"key\": \"value\"} via the API/CLI');\n    renderRawJsonView(data);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Always write KV secrets as flat key/value objects (vault kv put secret/foo key=value)","Validate write payloads in scripts: JSON.stringify of an array or scalar at the top level will break the editor","Store lists as a string value under a key, never as the top-level payload"],"tags":["kv","json","validation","secret-editing"],"backgroundTag":null,"analyzedSha":"744b611b5700b3b7f82d76b4d6938a91b9989367","analyzedAt":"2026-08-15T14:40:29.333Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}