28
votes
Accepted
How do you fix the wrong-case-sensitivity dictionary setting bug-pattern?
Well, do you see the problem with this? Because we put a public setter on there.
So don't have a public setter.
Create a new class CaseInsensitiveDictionary that contains a private Dictionary ...
23
votes
Accepted
Is it a bad idea to pass JSON objects on the query string for an API "search" operation?
Its not a brilliant idea. The URI is not really a good place for data of unpredictable length, and although there is no 'official' maximum length, many webservers apply their own limit (IIS is 2083 ...
15
votes
JSON without quotes for keys
It sounds like you are looking for a data-serialization format that is human-readable and version-control-friendly but not as strict about quotes as JSON.
Such formats include:
Relaxed JSON (RJSON) (...
14
votes
JSON without quotes for keys
Keys in a JSON dictionary are not quoted strings, they are strings. Strings in JSON start with a quote, continue with escaped or unescaped characters, and end with a string. You can’t have different ...
14
votes
Accepted
What is the normal form of JSON? What is theory that you can't automate normalizing?
In short
JSON is a data representation according to a schema-less syntax without predefined semantics. On the opposite, normal forms are defined for abstract data model with a relational semantic ...
13
votes
Is it a good practice to have a special value "ALL" in an enum
Depends on whether your available eras are available to the calling application. Presumably they are so the user can select what they're interested in. If that's the case then it's a front-end issue ...
12
votes
How to represent a set in JSON?
Don't try to represent sets in JSON. Do it when parsing the data instead.
Your JSON data should have a schema which specifies which fields should be treated as a set, or you may have a metadata ...
12
votes
How should an API handle unsupported fields?
Whether the API rejects or ignores unsupported fields is a concern for the documentation used by consumers. Pick one, and then document this behavior so clients know what to expect. Let them decide ...
11
votes
Accepted
Why protobuf is said to be in binary format although we write it in text format similar to json
This would be more clear if you were comparing two more similar pieces of data with non-text data components.
For example, the following JSON is ALL text:
{
"NumberOfClients": 20
}
The 20 is two ...
11
votes
Is there a canonical way to handle JSON data format changes?
Problems
Generally speaking, handling different versions of the same data model in the same code results in extra unwanted complexity. Some common issues include:
Fields renamed
Data types changed
...
11
votes
How do you fix the wrong-case-sensitivity dictionary setting bug-pattern?
mmathis's answer gives you the practical solution to the problem, but I'll look at this from a more theoretical point of view.
What you're looking at here is a very close corollary of the Liskov ...
10
votes
Accepted
Keeping a JSON copy of a database
Basic Drawbacks
Excess complexity, redundancy. More potential for bugs (more paths through more code), more time to develop, test, and more cost to maintain, forever.
Stale Data
The moment the ...
9
votes
REST API - Should API Return Nested JSON Objects?
I second the approach presented here https://www.slideshare.net/stormpath/rest-jsonapis
In short, include the nested resource as links in the parent resource, meanwhile, provide an expand parameter ...
9
votes
Accepted
Should REST API return escaped user generated content
It belongs to the API to correctly serialize JSON: the user is not expected to be able to break JSON schema by introducing characters considered special in JSON, such as the quote character.
It doesn'...
9
votes
Accepted
Should error codes in JSON be integers or strings?
I would go with text. It's OK to have a string where you only use numbers. As a rule of thumb: you should not use integers for things that are not mathematical in nature. That is, if you can do ...
9
votes
Accepted
How do you pass enums between microservices, without need to have copies of enums in different services?
Yes and No, You should have a client and model library published as part of the API project.
Consumers of the api can use this library. So they will be deserialising to the same dtos or entities that ...
9
votes
How do you fix the wrong-case-sensitivity dictionary setting bug-pattern?
A option I used in the past, as an alternative to an CaseInsensitiveDictionary was a CaseInsensitiveString type.
public readonly struct CaseInsensitiveString : IEquatable<CaseInsensitiveString&...
8
votes
How deeply can a JSON object be nested?
Many JSON parsers and formatters use recursion (i.e., ArduinoJSON and the IBM DastaPower Gateway).
This means that deeply nested JSON objects can be used to attack implementations that use this ...
8
votes
How should an API handle unsupported fields?
This comment is very relevant.
It is only an internal API. The argument of the consumers is that they will ask me to support the age field ans want to start changing their app and send that field ...
7
votes
Inserting JSON document with `.` in key to MongoDB
There are a few alternatives:
1. Replace dots by a dash.
This would be my favorite approach, as it keeps the structure explicit enough.
Since according to you, “it is pretty much a one time ...
6
votes
Is it a good practice to have a special value "ALL" in an enum
If no eras provided in the input, then this book is considered to cover all eras.
This, and also having a special 'ALL' case, are bad IMHO - your APIs should be explicit where possible. Having special ...
6
votes
Web API Response, Error Code Convention
How can you know which field caused this error?
Make it explicit?
401 # The HTTP "Unauthorized" code is outside the JSON.
{
"message": "Your credentials cannot be accepted",
"invalid_fields": [
...
6
votes
Accepted
When does a JSON object become a burden on memory?
There is no general rule, but here's a suggestion.
Retrieve everything in one request unless the retrieval and loading takes too long.
If it's awkward to retrieve in one request and you would save ...
6
votes
Accepted
How to create useful error messages in a JSON REST API without leaking implementation details across layers?
You are probably trying to generate the JSON error information at the wrong level in your architecture.
If you convert data from one format to another at a layer boundary (like going from PersonInput ...
6
votes
Why not program our video text terminals/terminal emulators to use something JSON or XML on the backend instead of ANSI escape sequences?
Your question is sort of like saying assembly is difficult to work with, so computers should use higher level languages instead. The ANSI format is the right level of abstraction for working with ...
6
votes
Should error codes in JSON be integers or strings?
I'd suggest to a static constant string to both be able to map to i18n and keep expressiveness.
Something like this is nice:
{
error: 'invalid_id'
}
And you can even scope it to module to locate ...
6
votes
Accepted
Constantly writing a JSON file
The last time I had a requirement like that, the process looked like
When starting a new file, write the characters [\n to it to open a JSON array.
When appending to an existing file, seek to the end....
6
votes
How should an API handle unsupported fields?
REST APIs publish contracts so that consumers may know how to use them.
A contract is a written agreement between the publisher and consumer.
Extraneous fields can be handled however you like, ...
6
votes
How should an API handle unsupported fields?
The Robustness principle, also called "Postel's law" states:
be conservative in what you do, be liberal in what you accept from others
For your case it means to accept the unknown fields ...
5
votes
JSON Web Token - why is the payload public?
The use of the term signature in the RFC is analogous to a digital signature in asymmetric cryptography. In asymmetric cryptography if the sender encrypts a message with their private key, anyone who ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
json × 361rest × 71
api × 47
java × 46
api-design × 40
javascript × 36
c# × 24
database × 24
xml × 24
design × 20
data-structures × 17
web-services × 17
php × 14
python × 13
web-api × 13
design-patterns × 11
serialization × 11
web-development × 10
nosql × 10
ajax × 10
sql × 9
asp.net × 9
data × 9
architecture × 8
database-design × 8