question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSON::ParserError when response body contains a JSON primitive

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
neilcampbellcommented, Apr 8, 2020

This will be available in PactNet 2.5.3, which is building as we speak.

1reaction
bethesquecommented, Apr 8, 2020

My bad, 1.82.3. Travis has just taken a really long time to kick off the build.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found