Where is JSON in the result givent by the code provided by postman?


I test this url https://api.matchbook.com/bpapi/rest/security/session with a POST and a JSON in the body containing my credentials and it works fine, i get as a result a nice JSON like this (i deleted some values in there) :slight_smile:
“session-token”: “”,
“user-id”: 159754,
“role”: “USER”,
“account”: {
“email”: “”,
“username”: “”,
“balance”: 0,
“exposure”: -0.00000505,
“language”: “English”,
“address”: {
“country”: {
“country-id”: 52,
“name”: “”,
“country-code”: “CUR”
“address-id”: 110199,
“address-line-1”: “”,
“address-line-2”: “”,
“post-code”: “”
“currency”: “EUR”,
“id”: 756412,
“name”: {
“title”: “Mr”,
“first”: “”,
“last”: “”,
“title-id”: “”
“date-of-birth”: “”,
“phone-number”: “”,
“free-funds”: 0.00067,
“commission-credit”: 0,
“language-id”: 1,
“currency-id”: 2,
“odds-type-id”: “DECIMAL”,
“odds-type”: “DECIMAL”,
“bet-confirmation”: false,
“display-p-and-l”: true,
“exchange-type-id”: “BACKLAY”,
“exchange-type”: “back-lay”,
“odds-rounding”: true,
“user-security-question”: {
“user-security-question-id”: 71730,
“question”: {
“security-question-id”: 5,
“security-question”: “”
“answer”: “”
“bet-slip-pinned”: true
“last-login”: “2018-04-24T22:22:41.000Z”

This is cool until i click on code as i look for c# code and i’m given :slight_smile:

var client = new RestClient(“https://api.matchbook.com/bpapi/rest/security/session”);
var request = new RestRequest(Method.POST);
request.AddHeader(“Postman-Token”, “dcd363f4-f088-4a3a-b754-fec2272700e9”);
request.AddHeader(“Cache-Control”, “no-cache”);
request.AddHeader(“Content-Type”, “application/json”);
request.AddParameter(“undefined”, “{\r\n “username”: “UserNameValue”,\r\n “password”: “PasswordValue”\r\n}”, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

This code works but result is not JSON. It looks like this

“{“session-token”:“136170_9f977dd3f0bdac1459296b50e3604b”,“user-id”:458762,“role”:“USER”,“account”:{“email”:“UserNameValue@mb.com”,“username”:“UserNameValue”,“balance”:0.00,“exposure”:-0.00000505,“language”:“English”,“address”:{“country”:{“country-id”:52,“name”:“okokok”,“country-code”:“CUR”},“address-id”:110199,“address-line-1”:“Dr. M.J Hugenholtzweg”,“address-line-2”:“Z/H. UTS- Gebouw”,“post-code”:“12341234”},“currency”:“EUR”,“id”:754123,“name”:{“title”:“Mr”,“first”:“Asian”,“last”:“Connect NV”,“title-id”:“MR”},“date-of-birth”:“1980-01-01T05:00:00.000Z”,“phone-number”:“1324123411”,“free-funds”:0.00067000,“commission-credit”:0E-8,“language-id”:1,“currency-id”:2,“odds-type-id”:“DECIMAL”,“odds-type”:“DECIMAL”,“bet-confirmation”:false,“display-p-and-l”:true,“exchange-type-id”:“BACKLAY”,“exchange-type”:“back-lay”,“odds-rounding”:true,“user-security-question”:{“user-security-question-id”:71730,“question”:{“security-question-id”:5,“security-question”:“question”},“answer”:“answer”},“bet-slip-pinned”:true},“last-login”:“2018-04-24T22:46:54.000Z”}”

So the related c# code does not reflect what postman itself get as a result.
Where is the JSON content? ie What do change in the code? or how to ask postman for the correct c# code?

@Kynao - Everything is perfectly fine in the code generated.
As I can see that the result where you’re saying is not JSON is actually having extra quotes at the end and the beginning of the result.
In the beginning, it’s like "{"session-token... and the end of the result is ...000Z"}"

All you have to do is remove the extra quotes i.e. " from the start and the end and then it’s a valid JSON.

    "session-token": "136170_9f977dd3f0bdac1459296b50e3604b",
    "user-id": 458762,
    "role": "USER",
    "account": {
        "email": "UserNameValue@mb.com",
        "username": "UserNameValue",
        "balance": 0,
        "exposure": -0.00000505,
        "language": "English",
        "address": {
            "country": {
                "country-id": 52,
                "name": "okokok",
                "country-code": "CUR"
            "address-id": 110199,
            "address-line-1": "Dr. M.J Hugenholtzweg",
            "address-line-2": "Z/H. UTS- Gebouw",
            "post-code": "12341234"
        "currency": "EUR",
        "id": 754123,
        "name": {
            "title": "Mr",
            "first": "Asian",
            "last": "Connect NV",
            "title-id": "MR"
        "date-of-birth": "1980-01-01T05:00:00.000Z",
        "phone-number": "1324123411",
        "free-funds": 0.00067,
        "commission-credit": 0,
        "language-id": 1,
        "currency-id": 2,
        "odds-type-id": "DECIMAL",
        "odds-type": "DECIMAL",
        "bet-confirmation": false,
        "display-p-and-l": true,
        "exchange-type-id": "BACKLAY",
        "exchange-type": "back-lay",
        "odds-rounding": true,
        "user-security-question": {
            "user-security-question-id": 71730,
            "question": {
                "security-question-id": 5,
                "security-question": "question"
            "answer": "answer"
        "bet-slip-pinned": true
    "last-login": "2018-04-24T22:46:54.000Z"

Thanks you sivcan. Yes i already tried removing quotes but given this supposed JSON :

{“session-token”:“136170_c459f4d364f4b9253777f9ebfd53433”,“user-id”:136170,“role”:“USER”,“account”:{“email”:“Asiaconn391@mb.com”,“username”:“Asiaconn391”,“balance”:0.00,“exposure”:-0.00000505,“language”:“English”,“address”:{“country”:{“country-id”:52,“name”:“Curacao”,“country-code”:“CUR”},“address-id”:110199,“address-line-1”:“Dr. M.J Hugenholtzweg”,“address-line-2”:“Z/H. UTS- Gebouw”,“post-code”:“12341234”},“currency”:“EUR”,“id”:120247,“name”:{“title”:“Mr”,“first”:“Asian”,“last”:“Connect NV”,“title-id”:“MR”},“date-of-birth”:“1980-01-01T05:00:00.000Z”,“phone-number”:“1324123411”,“free-funds”:0.00067000,“commission-credit”:0E-8,“language-id”:1,“currency-id”:2,“odds-type-id”:“DECIMAL”,“odds-type”:“DECIMAL”,“bet-confirmation”:false,“display-p-and-l”:true,“exchange-type-id”:“BACKLAY”,“exchange-type”:“back-lay”,“odds-rounding”:true,“user-security-question”:{“user-security-question-id”:71730,“question”:{“security-question-id”:5,“security-question”:“Your favourite holiday destination?”},“answer”:“Cork”},“bet-slip-pinned”:true},“last-login”:“2018-04-25T01:31:51.000Z”}

i fullfilled into http://json2csharp.com/ and the result is : "Parsing your JSON didn’t work. Please make sure it’s valid. "

So i tried https://app.quicktype.io/ but result is “Key must be quoted”

Also, apprenlty, i can’t give you my exact json because once i submit the string on this forum, the submitted string is transformed. The original one is full of \
Example => string {\“session-token\”:\“136170_c459f4d364f4b9253777f9ebfd53433\”,\“user-id\”: and so on

Ohhh, I guess I got your problem.

  1. You can always use the three backticks like this : ``` enter code here… ``` around your code and then your code will be properly formatted when you’ll be pasting it here on the discourse.

  2. Your JSON is actually stringified. Since it starts with " and ends with " also it has backslashes i.e. \ so, you definitely have a stringified JSON.
    The solution to this problem is that you’ll have to do a JSON.parse(response) and it should work out of the box. (This is for javascript)

Since you’re using C# then you might want to check out this resources as to how you can parse the JSON


Thanks you sivcan, you made it.
I previously recorded several solutions presented in some web pages i had to investigated but you bring the one which is the easiest corresponding to this guide and it works fine https://weblog.west-wind.com/posts/2015/mar/31/prettifying-a-json-string-in-net

1 Like