Json from API To DataSet

Sorry If this is a dead post but this situation is exactly what I am experiencing. I am using an API connection to Dayforce inside of a function I will later use to write to the employee table. I tried the method above but getting an error.
Here is the code

var client ="apiUrlHere";
var restClient = new RestClient(client);

var response = restClient.Execute(request);
string dsTemp = $"{{newEmployee: [{response}]}}";
this.output = JsonConvert.DeserializeObject<DataSet>(dsTemp);

the error I get in Postman when trying to call the function is:
Sorry! Something went wrong. Please contact your system administrator. Correlation Id: b2ea37ff-5e2c-468f-865e-29adee6f54be

the log file has a lot. I can post more, but the base of it is:
<![CDATA[Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: R. Path ‘newEmployee’, line 1, position 17.

Calling the API in Postman I get the below data:
{
“Data”: {
“EmployeeNumber”: “115165”,
“FirstName”: “Matthew”,
“LastName”: “Best”
}
}

string dsTemp = $"{{\"newEmployee\": [{response}]}}";

I tried this and I get what looks like the same error in the log.

I see it now, just can’t write on my phone.

2 Likes

Sorry, I forgot.

I ran this in a function with output being a DataSet

string response =
@"{
    'Data': {
        'EmployeeNumber': '115165',
        'FirstName': 'Matthew',
        'LastName': 'Best'
    }
}".Replace("'", "\"");

//using Newtonsoft.Json;
//using Newtonsoft.Json.Linq;

string dsTemp = $"{{\"newEmployee\": [{JToken.Parse(response).SelectToken("Data").ToString()}]}}";

output = JsonConvert.DeserializeObject<DataSet>(dsTemp);

The result:

{
  "output": {
    "newEmployee": [
      {
        "EmployeeNumber": "115165",
        "FirstName": "Matthew",
        "LastName": "Best"
      }
    ]
  }
}
1 Like

That gave me the format I needed. Thank you.