{"record":{"id":"a5f337bae6ed1bc6","repo":"puppetlabs/puppet","slug":"could-not-parse-json-metadata-path","errorCode":null,"errorMessage":"Could not parse JSON %{metadata_path}","messagePattern":"Could not parse JSON %(.+?)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/module_tool/applications/application.rb","lineNumber":59,"sourceCode":"        return @metadata if @metadata\n\n        @metadata = Puppet::ModuleTool::Metadata.new\n\n        unless @path\n          raise ArgumentError, _(\"Could not determine module path\")\n        end\n\n        if require_metadata && !Puppet::ModuleTool.is_module_root?(@path)\n          raise ArgumentError, _(\"Unable to find metadata.json in module root at %{path} See https://puppet.com/docs/puppet/latest/modules_publishing.html for required file format.\") % { path: @path }\n        end\n\n        metadata_path = File.join(@path, 'metadata.json')\n\n        if File.file?(metadata_path)\n          File.open(metadata_path) do |f|\n            @metadata.update(Puppet::Util::Json.load(f))\n          rescue Puppet::Util::Json::ParseError => ex\n            raise ArgumentError, _(\"Could not parse JSON %{metadata_path}\") % { metadata_path: metadata_path }, ex.backtrace\n          end\n        end\n\n        if File.file?(File.join(@path, 'Modulefile'))\n          Puppet.warning _(\"A Modulefile was found in the root directory of the module. This file will be ignored and can safely be removed.\")\n        end\n\n        @metadata\n      end\n\n      def load_metadata!\n        @metadata = nil\n        metadata(true)\n      end\n\n      def parse_filename(filename)\n        match = /^((.*?)-(.*?))-(\\d+\\.\\d+\\.\\d+.*?)$/.match(File.basename(filename, '.tar.gz'))\n        if match","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/module_tool/applications/application.rb#L41-L77","documentation":"Application#metadata raises ArgumentError('Could not parse JSON <path>') when Puppet::Util::Json.load fails with Puppet::Util::Json::ParseError while reading the module's metadata.json. The file exists but is not valid JSON (or not UTF-8 clean), so its contents cannot be trusted for build/install decisions. The original backtrace is attached as the third raise argument.","triggerScenarios":"metadata.json containing trailing commas, single quotes, comments, unescaped newlines in strings, or a UTF-8 BOM; hand-edited JSON with a missing closing brace; a file written by a tool that emits YAML or pretty-print with smart quotes. Puppet::Util::Json (multijson-backed strict JSON) rejects it and the rescue clause re-raises as ArgumentError.","commonSituations":"Manually editing metadata.json and breaking syntax; merge-conflict markers left in the file from a git merge; encoding issues when editing on Windows (BOM, CRLF inside string literals); tools that write JSON5.","solutions":["Validate the file with a strict JSON parser: `ruby -rjson -e 'JSON.parse(File.read(\"metadata.json\"))'` or `jq . metadata.json` to surface the exact line.","Fix the reported syntax issue (remove trailing commas/comments, quote keys with double quotes, close braces).","Remove git conflict markers after merges.","Re-save the file as UTF-8 without BOM."],"exampleFix":"// before\n{\n  'name': 'acme-web',  // single quotes and comment\n  \"version\": \"0.1.0\",\n}\n\n// after\n{\n  \"name\": \"acme-web\",\n  \"version\": \"0.1.0\"\n}","handlingStrategy":"try-catch","validationCode":"begin\n  Puppet::Util::Json.load(File.read('metadata.json'))\nrescue Puppet::Util::Json::ParseError => e\n  abort \"metadata.json is invalid: #{e.message}\"\nend","typeGuard":null,"tryCatchPattern":"begin\n  app.run\nrescue ArgumentError => e\n  if e.message.include?('Could not parse JSON')\n    abort \"fix metadata.json syntax: run `jq . metadata.json` to locate the error\"\n  end\n  raise\nend","preventionTips":["Lint metadata.json in CI with `jq empty metadata.json` or jsonlint before building modules.","Edit JSON with editors that validate syntax; avoid hand-writing with comments/trailing commas.","After git merges, run the jq check to catch conflict markers."],"tags":["puppet","json","metadata-json","parse-error"],"backgroundTag":"invalid-json","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}