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.

how to make JSON decoding throw an error for superfluous elements in JSON input

See original GitHub issue

Hi! How can I make the Circe JSON decoding stricter such that whenever it encounters an element (in the JSON input string) that is not in the target class X (decode[X](string)) it throws an error. Currently, with the default settings (circe 0.9.1), superfluous elements are silently ignored. For me (in my application) superfluous elements are an input error, so I need the error to be thrown by circe. Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
daddykotexcommented, Apr 20, 2018

I ask the following to learn more, not claim a solution by any means.

yeah, I answered just to share where I’ve seen this 😃

Why can’t you, per your example, make elements a required field then?

Well, that’s another perfectly valid solution in my opinion. One reason you might not be able to do that is that you have to support older clients, and elements is something new in the payload.

1reaction
hansschlcommented, Mar 6, 2018

@travisbrown Sure: I’ve tried the #708 example (with circe 0.9.1). In that example, decoding should work for good and shouldBeGood, although it does only for good.

Read more comments on GitHub >

github_iconTop Results From Across the Web

json — JSON encoder and decoder — Python 3.11.1 ...
It should return a JSON encodable version of the object or raise a TypeError . If not specified, TypeError is raised. If sort_keys...
Read more >
Can you use a trailing comma in a JSON object?
With Relaxed JSON, you can have trailing commas, or just leave the commas out. They are optional.
Read more >
JSON and serialization - Flutter documentation
By looking at the dart:convert documentation, you'll see that you can decode the JSON by calling the jsonDecode() function, with the JSON string...
Read more >
How to serialize and deserialize JSON using C# - .NET
Learn how to use the System.Text.Json namespace to serialize to and deserialize from JSON in .NET. Includes sample code.
Read more >
PARSE_JSON - Snowflake Documentation
If the PARSE_JSON function is called with an empty string, or with a string containing only whitespace characters, then the function returns NULL...
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