Home > other >  Why is JSON disregarding the escape?
Why is JSON disregarding the escape?

Time:08-05

JSON is disregarding the backslashes on line 3. I want whatever is between double quotes from line 3 to 18 as a string.

This is my JSON code:

{
    "schema":
    "syntax = \"proto3\";
    message SearchRequest {
        float eventVersion = 1;
        string producedBy = 2;
        string asupSubject = 3;
        int64 sysSerialNo = 4;
        int64 systemId = 5;
        string rawAsupPath = 6;
        int64 completedTimestamp = 7;
        string sourceQueue = 8;
        .SearchRequest.addonattributes addOnAttributes = 9;
  message addonattributes {
    string asupSecureType = 1;
    string sesgFlag = 2;
        }
    }",
  "schemaType": "PROTOBUF"
}

This is the output received:

{
    "error_code": 400,
    "message": "Illegal unquoted character ((CTRL-CHAR, code 13)): has to be escaped using backslash to be included in string value\n at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 3, column: 27] (through reference chain: io.confluent.kafka.schemaregistry.client.rest.entities.requests.RegisterSchemaRequest[\"schema\"])"
}

CodePudding user response:

Its actually the linebreaks that are breaking it. Try this:

{
    "schema":
    "syntax = \"proto3\";\n    message SearchRequest {\n        float eventVersion = 1;\n        string producedBy = 2;\n        string asupSubject = 3;\n        int64 sysSerialNo = 4;\n        int64 systemId = 5;\n        string rawAsupPath = 6;\n        int64 completedTimestamp = 7;\n        string sourceQueue = 8;\n        .SearchRequest.addonattributes addOnAttributes = 9;\n  message addonattributes {\n    string asupSecureType = 1;\n    string sesgFlag = 2;\n        }\n    }",
  "schemaType": "PROTOBUF"
}

Note: This works for you're initial text here, if you have other special characters in the future they will need escaped accordingly.

  •  Tags:  
  • json
  • Related