JSON::ParserError when response body contains a JSON primitive
See original GitHub issueI’m working on consumer and provider tests with PactNet, but have consistently run into ParserErrors when the response/request bodies contain primitives. As an example:
{
"description": "A GET request to retrieve a user's ID",
"providerState": "A user that exists in the System",
"request": {
"method": "get",
"path": "/api/users",
"query": "username=bill",
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json; charset=utf-8"
},
"body": "c43665eb-b9c8-4787-94b6-e19bd65c9225",
"matchingRules": {
"$.body": {
"match": "type"
}
}
}
}
It was claimed in issue #139 (before it was closed) that strings alone are not valid JSON, but as of at least Dec 2017 this is untrue. So it would be nice if this discrepancy could get resolved, or at least if some piece of documentation could clarify which JSON spec Pact expects services to follow. Thanks.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Invalid JSON primitive when sending POST request
Your issue is because you're not sending valid JSON. You need to wrap the keys in double quotes. Also, subscriptionJson is a literal...
Read more >Error parsing Json value in Rest API
To fix this error either change the JSON to a JSON primitive value (e.g. string, number, boolean, null) or change the deserialized type...
Read more >JSON Error when attempting to consume data from an ...
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is...
Read more >Cannot convert object to primitive value : r/learnjavascript
this gives me the error TypeError: Cannot convert object to primitive value. and when I don't use the JSON.parse (so: const data =...
Read more >CAST of Response:Entity to Json object fails with error 12869
The Json parser currently only recognizes JSON data when it is in the form of an {object} or an [array]. As a result,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This will be available in PactNet 2.5.3, which is building as we speak.
My bad, 1.82.3. Travis has just taken a really long time to kick off the build.