2

I figured this out while writing the question, but figured it might be useful to someone :)

I had code processing JSON from a callout, and it all worked fine, but when I put the exact same JSON in my mock, SF throws an error trying to parse it. I have validated the JSON and it is exactly what I receive in the actual callout.

The error says System.JSONException: Unexpected character ('n' (code 110)): was expecting comma to separate ARRAY entries at [line:1, column:232]

The 'n' is the first letter of 'name' in the JSON at column 232 here: ...state.completion", "[{\"name\":\"connect_adapt...

and the full string is below. Removing the escape quotes did not change anything, but clearly it seems related to them somehow.

{ 
    "columns":[ 
        { 
            "name":"chef_node_id"
        },
        { 
            "name":"serverHost"
        },
        { 
            "name":"metric_name"
        },
        { 
            "name":"checklist"
        }
    ],
    "warnings":[ 

    ],
    "values":[ 
        [ 
            "node-fvyhpgt2",
            "node-fvyhpgt2_coupa_software_3",
            "getting_started.state.completion",
            "[{\"name\":\"connect_adapters\",\"completed\":true}, {\"name\":\"examine_device\",\"completed\":true}, {\"name\":\"query_saved\",\"completed\":true}, {\"name\":\"device_tag\",\"completed\":false}, {\"name\":\"enforcement_executed\",\"completed\":false}, {\"name\":\"dashboard_created\",\"completed\":true}, {\"name\":\"report_generated\",\"completed\":true}]"
        ]
    ],
    "matchingEvents":0.0,
    "status":"success",
    "omittedEvents":0.0
}

1 Answer 1

2

ANSWER: Escape the escapes. Because this is being handled both in Apex and as JSON, it seems they both need their own "\". Or should I say \"\\". Sorry, bad joke. Maybe others can offer even more detailed explanation.

Change the part in question to: ...state.completion", "[{\\"name\\":\\"connect_adapt... and so on.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .