{"record":{"id":"b165f545b45a2ff2","repo":"ory/hydra","slug":"unable-to-decode-json-w","errorCode":null,"errorMessage":"unable to decode JSON: %w","messagePattern":"unable to decode JSON: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cmd_helper_client.go","lineNumber":32,"sourceCode":"\n\thydra \"github.com/ory/hydra-client-go/v2\"\n\t\"github.com/ory/x/flagx\"\n)\n\nfunc clientFromFlags(cmd *cobra.Command) (hydra.OAuth2Client, error) {\n\tif filename := flagx.MustGetString(cmd, flagFile); filename != \"\" {\n\t\tsrc := cmd.InOrStdin()\n\t\tif filename != \"-\" {\n\t\t\tf, err := os.Open(filename) // #nosec G304\n\t\t\tif err != nil {\n\t\t\t\treturn hydra.OAuth2Client{}, fmt.Errorf(\"unable to open file %q: %w\", filename, err)\n\t\t\t}\n\t\t\tdefer f.Close() //nolint:errcheck\n\t\t\tsrc = f\n\t\t}\n\t\tclient := hydra.OAuth2Client{}\n\t\tif err := json.NewDecoder(src).Decode(&client); err != nil {\n\t\t\treturn hydra.OAuth2Client{}, fmt.Errorf(\"unable to decode JSON: %w\", err)\n\t\t}\n\t\treturn client, nil\n\t}\n\n\treturn hydra.OAuth2Client{\n\t\tAccessTokenStrategy:               new(flagx.MustGetString(cmd, flagClientAccessTokenStrategy)),\n\t\tAllowedCorsOrigins:                flagx.MustGetStringSlice(cmd, flagClientAllowedCORSOrigin),\n\t\tAudience:                          flagx.MustGetStringSlice(cmd, flagClientAudience),\n\t\tBackchannelLogoutSessionRequired:  new(flagx.MustGetBool(cmd, flagClientBackChannelLogoutSessionRequired)),\n\t\tBackchannelLogoutUri:              new(flagx.MustGetString(cmd, flagClientBackchannelLogoutCallback)),\n\t\tClientName:                        new(flagx.MustGetString(cmd, flagClientName)),\n\t\tClientSecret:                      new(flagx.MustGetString(cmd, flagClientSecret)),\n\t\tClientUri:                         new(flagx.MustGetString(cmd, flagClientClientURI)),\n\t\tContacts:                          flagx.MustGetStringSlice(cmd, flagClientContact),\n\t\tFrontchannelLogoutSessionRequired: new(flagx.MustGetBool(cmd, flagClientFrontChannelLogoutSessionRequired)),\n\t\tFrontchannelLogoutUri:             new(flagx.MustGetString(cmd, flagClientFrontChannelLogoutCallback)),\n\t\tGrantTypes:                        flagx.MustGetStringSlice(cmd, flagClientGrantType),\n\t\tJwksUri:                           new(flagx.MustGetString(cmd, flagClientJWKSURI)),","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/cmd/cmd_helper_client.go#L14-L50","documentation":"clientFromFlags in cmd/cmd_helper_client.go wraps a json.Decoder failure with \"unable to decode JSON: %w\". The CLI reads the OAuth2 client definition from --file (or stdin) and must parse it into hydra.OAuth2Client; this error means the input is not valid JSON or not shaped as an OAuth2 client object.","triggerScenarios":"--file (or stdin via '-') containing malformed JSON, an exported JWT/id_token instead of a client object, YAML instead of JSON, trailing garbage, or a JSON array instead of an object.","commonSituations":"Pasting a client secret or token dump into the file, exporting from another tool in YAML, forgetting quotes around an empty file (0 bytes also fails), or curl output that was an HTML error page.","solutions":["Validate the file with jq . <file> and fix JSON syntax","Ensure the content is a JSON object with client fields (e.g. {\"client_name\":...}), not a token or array","If piping via '-', check the producing command outputs valid JSON","Re-export the client from Hydra as JSON (hydra get client <id> --format json)"],"exampleFix":"// before (file content)\nclient_name: my-app\n// after\n{\"client_name\": \"my-app\"}","handlingStrategy":"validation","validationCode":"var c hydra.OAuth2Client\nb, _ := os.ReadFile(p)\nif err := json.Unmarshal(b, &c); err != nil {\n    return fmt.Errorf(\"invalid client JSON: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    fmt.Fprintf(os.Stderr, \"JSON decode failed: %v - validate with jq\\n\", err)\n    os.Exit(1)\n}","preventionTips":["Validate JSON with jq before CLI invocation","Generate client JSON from hydra export commands","Keep files as plain objects, not arrays or tokens"],"tags":["cli","json","parsing"],"backgroundTag":"invalid-json","analyzedSha":"4174065ffb052799890f7480f5360a877a67ffc1","analyzedAt":"2026-09-03T14:52:41.581Z","contentChangedAt":"2026-09-03T14:52:41.581Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}