Hot answers tagged

102 votes
Accepted

How bad of an idea is it to use Python files as configuration files?

Using a scripting language in place of a config file looks great at first glance: you have the full power of that language available and can simply eval() or import it. In practice, there are a few ...
amon's user avatar
  • 134k
54 votes

How bad of an idea is it to use Python files as configuration files?

+1 to everything in amon's answer. I'd like to add this: You'll regret using Python code as your configuration language the first time you want to import the same configuration from within code ...
Celada's user avatar
  • 654
35 votes
Accepted

How to represent a set in JSON?

Well, you can't. As you said, you can represent arrays and dictionaries. You have two choices. Represent the set as an array. Advantage: Converting from set to array and back is usually easy. ...
gnasher729's user avatar
  • 44.7k
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 ...
mmathis's user avatar
  • 5,458
23 votes

How bad of an idea is it to use Python files as configuration files?

The other answers are already very good, I'll just bring my experience of real-world usage in a few projects. Pros They are mostly already spelled out: if you are in a Python program, parsing is a ...
Matteo Italia's user avatar
23 votes
Accepted

Using a workaround instead of going the "standard" way in parsing json

Yes there is a downside: bugs in your half baked parser. Sure JSON is simple but you still can encounter tricky escaping situations. Just use an existing tried and true JSON parsing method and save ...
whatsisname's user avatar
  • 27.7k
22 votes
Accepted

Is it bad practice to use hyphens in JSON keys?

You can use anything as JSON keys, as long as it is valid UTF-8, doesn't contain zero code points, and it would be useful if you could represent the key as a string in the programming language of your ...
gnasher729's user avatar
  • 44.7k
22 votes
Accepted

Why would anyone use multipart/form-data for mixed data and file transfers?

multipart/form-data is a construct created for HTML forms. As you've discovered the positive of multipart/form-data is the transfer size is closer to the size of the object being transferred--where in ...
Samuel's user avatar
  • 9,187
21 votes
Accepted

How does Microdata rdfa compare to JSON-LD?

Microdata is not dead. While Microdata will not become a W3C standard¹, it’s still part of WHATWG’s HTML Living Standard. Differences between JSON-LD, Microdata, and RDFa (in the context of HTML ...
unor's user avatar
  • 1,122
21 votes
Accepted

Why do Microsoft's libraries depend on Newtonsoft.Json?

The most direct quote I've found is part of Scott Guthrie's announcement of the MVC 4 roadmap, back in 2012, (apparently offline but available via the Wayback Machine) which contains the following ...
Avner Shahar-Kashtan's user avatar
19 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 ...
richzilla's user avatar
  • 1,103
14 votes

Is it ineffecient to store data as json in plain text?

Is it less efficient to store a small bit of data like your example encoded in a string than as binary? Yes. How much less? Not enough to care. Is it less efficient to store thousands of such records ...
candied_orange's user avatar
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 ...
gnasher729's user avatar
  • 44.7k
14 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) (...
David Cary's user avatar
  • 1,442
13 votes

Is it bad practice to use hyphens in JSON keys?

There are plenty of JSON serialization systems that are more than capable of handling mapping between field names that aren't suitable for use in the language they integrate with. In most cases, they ...
Jules's user avatar
  • 17.7k
13 votes
Accepted

What JSON structure to use for key value pairs?

Whether you choose the first or the third option depends on your use case. If you are modeling many different instances of the same type of thing, choose the first. For example, you have a list of ...
Karl Bielefeldt's user avatar
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 ...
LoztInSpace's user avatar
  • 1,169
11 votes

What's the best way to return an array as a response in a RESTful API?

The second option is also the preferred method for security reasons. Older browsers have a security vulnerability that allows other javascript code on the web page to steal your data if it's returned ...
Chuck's user avatar
  • 211
11 votes

What JSON structure to use for key value pairs?

You say these are key / value pairs. In that case, use #3: dictionary of key / value pairs. If these are not key / value pairs, then don't call them "keys" and "values" and use #2, an array of ...
gnasher729's user avatar
  • 44.7k
11 votes
Accepted

REST API: Handle "partial" nested objects

In REST you can see everything you listed as a different resource. It is a different approach. In general you want to denormalize (database term) the data in a REST resource to fit your use case. So ...
Luc Franken's user avatar
  • 2,773
11 votes

Why is elastic search popular?

MongoDB is a database. Elasticsearch is a search engine. Since their aims are different, they have different priorities. MongoDB is focused on storing data consistently with good performance and to ...
Samuel's user avatar
  • 9,187
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 ...
TheCatWhisperer's user avatar
11 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 ...
Greg Burghardt's user avatar
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 ...
Philip Kendall's user avatar
10 votes
Accepted

Adding to a finite set of options; an API breaking change?

If the documentation described this field as being one of Dog, Cat, or Fish, then yes, adding another type changes the interface in a backwards-incompatible way. It is entirely conceivable that a ...
amon's user avatar
  • 134k
10 votes

Flat or nested JSON for hierarchal data?

Depends on your use case. When using JSON with statica typed languages, there is a huge bonus if your structure maps to your types. This means that all the names of the keys should be known in ...
fdreger's user avatar
  • 268
10 votes
Accepted

Base64 in Json: Is it a Good Idea for Rest API?

Base64 is a safe encoding for JSON. The downside to using Base64 is that it's quite verbose. It can add significant overhead to your file upload which means longer upload and more bandwidth used. If ...
Samuel's user avatar
  • 9,187
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 ...
joshp's user avatar
  • 3,481
9 votes

How to represent object references in JSON?

For inspiration, you may want to look into the way some of the json based api's (ex: json api, HAL) handle embedding. One simple answer is to track your data in a key value store. For example { "/...
VoiceOfUnreason's user avatar
9 votes

How bad of an idea is it to use Python files as configuration files?

The main question is: do you want your configuration file to be in some Turing complete language (like Python is)? If you do want that, you might also consider embedding some other (Turing complete) ...
Basile Starynkevitch's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible