{"record":{"id":"e7eecbf01068deeb","repo":"provectus/kafka-ui","slug":"s-is-not-valid-json","errorCode":null,"errorMessage":"'%s' is not valid json","messagePattern":"'(.+?)' is not valid json","errorType":"validation","errorClass":"ValidationException","httpStatus":400,"severity":"error","filePath":"kafka-ui-api/src/main/java/com/provectus/kafka/ui/serdes/builtin/sr/Serialize.java","lineNumber":47,"sourceCode":"import org.apache.avro.io.DatumWriter;\nimport org.apache.avro.io.EncoderFactory;\n\nfinal class Serialize {\n\n  private static final byte MAGIC = 0x0;\n  private static final ObjectMapper JSON_SERIALIZE_MAPPER = Jackson.newObjectMapper(); //from confluent package\n\n  private Serialize() {\n  }\n\n  @KafkaClientInternalsDependant(\"AbstractKafkaJsonSchemaSerializer::serializeImpl\")\n  @SneakyThrows\n  static byte[] serializeJson(JsonSchema schema, int schemaId, String value) {\n    JsonNode json;\n    try {\n      json = JSON_SERIALIZE_MAPPER.readTree(value);\n    } catch (JsonProcessingException e) {\n      throw new ValidationException(String.format(\"'%s' is not valid json\", value));\n    }\n    try {\n      schema.validate(json);\n    } catch (org.everit.json.schema.ValidationException e) {\n      throw new ValidationException(\n          String.format(\"'%s' does not fit schema: %s\", value, e.getAllMessages()));\n    }\n    try (var out = new ByteArrayOutputStream()) {\n      out.write(MAGIC);\n      out.write(schemaId(schemaId));\n      out.write(JSON_SERIALIZE_MAPPER.writeValueAsBytes(json));\n      return out.toByteArray();\n    }\n  }\n\n  @KafkaClientInternalsDependant(\"AbstractKafkaProtobufSerializer::serializeImpl\")\n  @SneakyThrows\n  static byte[] serializeProto(SchemaRegistryClient srClient,","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/provectus/kafka-ui/blob/83b5a60cc08501b570a0c4d0b4cdfceb1b88d6b7/kafka-ui-api/src/main/java/com/provectus/kafka/ui/serdes/builtin/sr/Serialize.java#L29-L65","documentation":"serializeJson first parses the supplied value with a JSON mapper before validating it against the registered JSON Schema. If the string cannot be parsed as JSON at all, it throws this ValidationException instead of a schema error, telling you the value is syntactically invalid JSON.","triggerScenarios":"Producing via the kafka-ui messages API with the Json (Schema Registry JSON schema) serde and a value parameter that fails Jackson readTree parsing - e.g. single quotes instead of double quotes, missing quotes around strings, trailing commas, unescaped control characters, or plain text.","commonSituations":"Hand-typing a value in the UI produce form without proper JSON quoting; shell/curl quoting mangled the JSON body; copied values that got double-escaped or unescaped; sending a bare string or number without valid JSON syntax.","solutions":["Validate the value with a JSON parser (jq, jsonlint) before producing","Ensure string values are quoted, e.g. \"my value\" not my value","Verify shell/curl quoting didn't strip or double-escape quotes in API calls","Check the value string in the error message to see exactly what failed parsing"],"exampleFix":"// before\nString value = \"{'key': 'val'}\"; // single quotes are invalid JSON\n// after\nString value = \"{\\\"key\\\": \\\"val\\\"}\";","handlingStrategy":"validation","validationCode":"ObjectMapper m = new ObjectMapper();\ntry { m.readTree(value); } catch (JsonProcessingException e) {\n  throw new IllegalArgumentException(\"value is not valid JSON: \" + e.getOriginalMessage());\n}","typeGuard":null,"tryCatchPattern":"try {\n  produceMessage(topic, value);\n} catch (ValidationException e) {\n  // value failed JSON parsing; surface message before retry\n  System.err.println(e.getMessage());\n}","preventionTips":["Run jq or a JSON linter over the payload before producing","In API calls, put the JSON in a properly quoted field and verify shell escaping","Build payloads with a JSON library (Jackson, Gson) rather than string concatenation"],"tags":["kafka","json","serialization","validation"],"backgroundTag":"json-parse-error","analyzedSha":"83b5a60cc08501b570a0c4d0b4cdfceb1b88d6b7","analyzedAt":"2026-09-08T04:35:39.002Z","contentChangedAt":"2026-09-08T04:35:39.002Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}