{"record":{"id":"6f781b569bdd8561","repo":"puppetlabs/puppet","slug":"could-not-parse-json-data-for-name-key-de","errorCode":null,"errorMessage":"Could not parse JSON data for %{name} %{key}: %{detail}","messagePattern":"Could not parse JSON data for %(.+?) %(.+?): %(.+?)","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/indirector/json.rb","lineNumber":71,"sourceCode":"  def data_dir\n    Puppet.run_mode.server? ? Puppet[:server_datadir] : Puppet[:client_datadir]\n  end\n\n  def load_json_from_file(file, key)\n    json = nil\n\n    begin\n      json = Puppet::FileSystem.read(file, :encoding => Encoding::BINARY)\n    rescue Errno::ENOENT\n      return nil\n    rescue => detail\n      raise Puppet::Error, _(\"Could not read JSON data for %{name} %{key}: %{detail}\") % { name: indirection.name, key: key, detail: detail }, detail.backtrace\n    end\n\n    begin\n      from_json(json)\n    rescue => detail\n      raise Puppet::Error, _(\"Could not parse JSON data for %{name} %{key}: %{detail}\") % { name: indirection.name, key: key, detail: detail }, detail.backtrace\n    end\n  end\n\n  def from_json(text)\n    model.convert_from('json', text.force_encoding(Encoding::UTF_8))\n  end\n\n  def to_json(object)\n    object.render('json')\n  end\nend\n","sourceCodeStart":53,"sourceCodeEnd":83,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/indirector/json.rb#L53-L83","documentation":"After a successful binary read of the stored file, model.convert_from('json', text) raised - the stored bytes are not valid JSON for the model. Raised as Puppet::Error 'Could not parse JSON data for <indirection> <key>: <detail>', where detail is the parser's message (unexpected token, EOF, schema mismatch). Corruption here means the file was truncated, hand-edited, or written by an incompatible puppet version.","triggerScenarios":"find/search hitting a corrupted store/cache file: disk-full truncation, a kill during a non-atomic write, manual edits to datadir files, or a downgrade opening files serialized by a newer puppet version.","commonSituations":"Crash loops during disk-pressure events; operators hand-editing stored json; version rollbacks after upgrades changed serialization; tools that rewrite datadir files in place.","solutions":["Identify the file from the key: <datadir>/<indirection>/<key>.json and validate it (jq . file, or ruby -rjson -e 'JSON.parse(File.read(ARGV[0]))' file).","If the entry is regenerable (node cache, facts), delete it; Puppet recreates it on the next request.","For non-regenerable stores, restore the file from backup.","Fix the root cause: keep datadirs off full disks and never let external tools edit store files in place."],"exampleFix":"# before: corrupted store entry\n# Could not parse JSON data for node node1.example.com: 859: unexpected token at '...'\n\n# after: drop the regenerable cache entry\nrm \"$(puppet config print server_datadir)/node/node1.example.com.json\"\n# the next request rebuilds it","handlingStrategy":"fallback","validationCode":"file = store_path_for(key)\nif File.exist?(file)\n  JSON.parse(Puppet::FileSystem.read(file)) rescue(throw :corrupt_entry)\nend","typeGuard":null,"tryCatchPattern":"begin\n  data = Puppet::Node.indirection.find(key)\nrescue Puppet::Error => e\n  if e.message.include?('Could not parse JSON data')\n    Puppet::Node.indirection.destroy(key) # ENOENT-safe removal\n    data = Puppet::Node.indirection.find(key) # rebuild the entry\n  else\n    raise\n  end\nend","preventionTips":["Never let external tools edit store files in place.","Monitor disk space where datadirs live.","Alert on parse failures and auto-prune regenerable entries."],"tags":["puppet","json-store","corruption","serialization","cache"],"backgroundTag":"corrupt-json-file","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}