Rest send data

Datatable saves data as: {id:1,other:'data'}

How to force enclose properties names and string data with double quotes, ", as:

{"id": 1, "other": "data"}

Tagged:

Comments

  • edited December 2

    Hello @paulo_martins,

    How to force enclose properties names and string data with double quotes, "

    I take it you want to send a server request in the format of a JSON string? Such modification is indeed possible, since you can change the parameters of any server request that is being issued on the client-side. A custom proxy object can be used to process the request parameters (you can also provide any additional logic to process the server request in general). The proxy should return either a promise, or a data object.

    For instance, you can take the original request parameters and convert them to a JSON string: https://snippet.webix.com/pc4e1dqu (try adding/deleting a row and looking at the request details).

  • edited December 3

    Thank you!
    This partly solves the problem, but json.stringify serializes some number values, such as strings, while the api server expects a number type.

    Source of datatable:

    {"id":1,"username":"frank","euid":1,"euidc":2,"euname":"frank","ad":0,"pin":"5511","password":"","email":"abc@gmail.com","profiles":"14","alogin":0,"access":0}
    

    JSON.Stringify results in a request:

    {"id":1,"username":"franklin 3","euid":"1","euidc":"2","euname":"Franklin","ad":0,"pin":"5511","password":"","email":"defrank@gmail.com","profiles":"14","alogin":0,"access":0}
    

    that generates this response:

    {error: {statusCode: 422, name: "UnprocessableEntityError",…}}
    error: {statusCode: 422, name: "UnprocessableEntityError",…}
    statusCode: 422
    name: "UnprocessableEntityError"
    message: "The request body is invalid. See error object `details` property for more info."
    code: "VALIDATION_FAILED"
    details: [{path: ".euid", code: "type", message: "should be number", info: {type: "number"}},…]
    0: {path: ".euid", code: "type", message: "should be number", info: {type: "number"}}
    path: ".euid"
    code: "type"
    message: "should be number"
    info: {type: "number"}
    type: "number"
    1: {path: ".euidc", code: "type", message: "should be number", info: {type: "number"}}
    path: ".euidc"
    code: "type"
    message: "should be number"
    info: {type: "number"}
    type: "number"
    

    If you can help me ...

  • edited December 9

    This partly solves the problem, but json.stringify serializes some number values, such as strings, while the api server expects a number type.

    This simply means that the original value was provided as such (in a form of a string), or was converted in the process. Still, this can be avoided by converting the values back to the number type just before issuing a server request. Please take a look at the following example: https://snippet.webix.com/jhtk569g.

  • Thanks, I resolved with a proxy, converted the values first and submitted later. However the source for datatable is in the form of number and I still don't understand why some are changed and some are not.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!