#Error occurred when parsing json response that has hyphen in keys

1 messages · Page 1 of 1 (latest)

noble parrot
#

Following exception occurred when try to parse JSON response. Which contain a key with name job-name

error PayloadBindingClientError ("Payload binding failed: {ballerina/lang.value}ConversionError",error("{ballerina/lang.value}ConversionError"))
time = 2024-01-16T11:06:59.700+05:30 level = ERROR module = "" message = "Error while getting pods: " error = "Payload binding failed: {ballerina/lang.value}ConversionError"

Used the following type to parse the response

type Student record {
    string user;
    string job\-name?;
};

But if you ignore the string job\-name?; from the type and try to member access it is working fine. Any help?

spare ice
#

Can you please share the Ballerina version and any code snippets, sample JSON, etc. if possible?

I tried the following on 2201.8.2, and the conversion worked as expected.

import ballerina/http;
import ballerina/io;

type Student record {
    string user;
    string job\-name?;
};

service on new http:Listener(8080) {
    resource function post test(Student st) {
        io:println(st); // {"user":"Joy","job-name":"Eng"}
    }
}
$ curl -v -X POST --data '{"user": "Joy", "job-name": "Eng"}' "http://localhost:8080/test" --header "Content-Type:application/json"
noble parrot
#

Can you consider this example?
Bal version: Ballerina 2201.7.0 (Swan Lake Update 7)

spare ice
#

Looping in @lost radish and @solar ember

spare ice