{"record":{"id":"32fa7974577dfb18","repo":"getsops/sops","slug":"could-not-unmarshal-input-data-s-32fa79","errorCode":null,"errorMessage":"Could not unmarshal input data: %s","messagePattern":"Could not unmarshal input data: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"stores/json/store.go","lineNumber":338,"sourceCode":"\t\treturn sops.Tree{}, err\n\t}\n\tbranches, metadata, err := stores.ExtractMetadata(branches, stores.MetadataOpts{\n\t\tFlatten: stores.MetadataFlattenNone,\n\t})\n\tif err != nil {\n\t\treturn sops.Tree{}, err\n\t}\n\treturn sops.Tree{\n\t\tBranches: branches,\n\t\tMetadata: metadata,\n\t}, nil\n}\n\n// LoadPlainFile loads plaintext json file bytes onto a sops.TreeBranches object\nfunc (store *Store) LoadPlainFile(in []byte) (sops.TreeBranches, error) {\n\tbranch, err := store.treeBranchFromJSON(in)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"Could not unmarshal input data: %s\", err)\n\t}\n\treturn sops.TreeBranches{\n\t\tbranch,\n\t}, nil\n}\n\n// EmitEncryptedFile returns the encrypted bytes of the json file corresponding to a\n// sops.Tree runtime object\nfunc (store *Store) EmitEncryptedFile(in sops.Tree) ([]byte, error) {\n\tbranches, err := stores.SerializeMetadata(in, stores.MetadataOpts{\n\t\tFlatten: stores.MetadataFlattenNone,\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"Error marshaling metadata: %s\", err)\n\t}\n\treturn store.EmitPlainFile(branches)\n}\n","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/getsops/sops/blob/13442bb98183887d7a9ac09ec8ab0564673a59d8/stores/json/store.go#L320-L356","documentation":"This error wraps any failure that occurs while parsing plaintext JSON input bytes into a sops.TreeBranches structure inside the JSON Store. The JSON store's LoadPlainFile feeds the raw bytes to treeBranchFromJSON, which uses encoding/json to decode into a tree; if the input is not valid JSON (or violates JSON value shapes), the underlying decoder error is surfaced wrapped with this message.","triggerScenarios":"Calling LoadPlainFile (or any higher-level path like LoadPlainData/decrypt workflows using the JSON store) with bytes that are not well-formed JSON: malformed syntax, trailing commas, comments, BOM bytes, empty input, or non-JSON binary data passed to the JSON store.","commonSituations":"Encrypting a file with the wrong format detection (e.g. a YAML file being processed by the JSON store), a .env or INI file passed to sops with --input-type json, corrupted downloads/partial writes of config files, or files starting with a UTF-8 BOM.","solutions":["Validate the input with a JSON parser (e.g. `jq . file`) to see the exact syntax error location","Ensure the correct sops format/store is used: match --input-type/-i to the real file format (yaml, ini, env, json)","Strip BOM and encoding issues: re-save the file as clean UTF-8 without BOM","Fix the reported JSON syntax error in the file (the wrapped %s contains the Go json error with offset)"],"exampleFix":"// before: wrong store for content\nstore := json.NewStore()\ntree, err := store.LoadPlainFile(yamlBytes) // \"Could not unmarshal input data\"\n// after: use the store matching the content\nstore := yaml.NewStore()\ntree, err := store.LoadPlainFile(yamlBytes)","handlingStrategy":"validation","validationCode":"func validateJSON(b []byte) error {\n\tb = bytes.TrimPrefix(b, []byte{0xEF, 0xBB, 0xBF}) // strip BOM\n\tif len(bytes.TrimSpace(b)) == 0 {\n\t\treturn errors.New(\"empty input\")\n\t}\n\tvar v interface{}\n\treturn json.Unmarshal(b, &v)\n}\nif err := validateJSON(input); err != nil {\n\treturn fmt.Errorf(\"not valid JSON: %w\", err)\n}\ntree, err := store.LoadPlainFile(input)","typeGuard":null,"tryCatchPattern":"tree, err := store.LoadPlainFile(data)\nif err != nil {\n\tif strings.HasPrefix(err.Error(), \"Could not unmarshal input data\") {\n\t\treturn fmt.Errorf(\"input is not valid JSON: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Validate input with jq or json.Unmarshal before calling sops store APIs","Match the sops --input-type/store to the actual file format","Save files as UTF-8 without BOM","Never feed binary or non-JSON data to the JSON store"],"tags":["json","unmarshal","parsing","input-validation"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"13442bb98183887d7a9ac09ec8ab0564673a59d8","analyzedAt":"2026-09-01T03:53:00.447Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}