Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Hot answers tagged

101 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 ...
user avatar
  • 123k
61 votes

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

In practice the second option is the best practice. Reason for this is that you cannot extend the resource at all when you just return an array. For example: If you need to add a count of all ...
user avatar
  • 2,564
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 ...
user avatar
  • 654
48 votes
Accepted

Using a relational database vs JSON objects for event/activity data

I think your question really boils down to: When should I use a NoSQL approach vs. RDBMS? You settled on JSON early (a NoSQL-ish decision), perhaps because you've got Ajax consumers. The answer of ...
user avatar
  • 1,697
44 votes
Accepted

null vs missing key in REST API Response

Consider removing empty or null values. If a property is optional or has an empty or null value, consider dropping the property from the JSON, unless there's a strong semantic reason for its existence....
user avatar
42 votes

Should a front-end developer ever specify JSON format for back-end developers?

This is a conversation you should be having together, discussing the requirements and pros and cons of different formats. If one side or the other is dictating what happens, you're going to end up ...
user avatar
  • 2,079
33 votes
Accepted

JSON Web Token - why is the payload public?

You choose not to encrypt the payload for the same reasons that you choose not to encrypt anything else: the cost (however small it is) exceeds the benefit, and a lot of data simply doesn't need to be ...
user avatar
30 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. ...
user avatar
  • 37.5k
28 votes

XSLT equivalent for JSON

XML : XSLT :: JSON : x. What is x ? The most facile answer would be x = JavaScript. Though you could make a case for this, it feels unsatisfying. Even though XSLT is technically Turing complete, ...
user avatar
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 ...
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 ...
user avatar
  • 27.2k
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 ...
user avatar
20 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 ...
user avatar
  • 37.5k
18 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 ...
user avatar
  • 1,043
17 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 ...
user avatar
  • 9,007
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 ...
user avatar
13 votes
Accepted

REST API - Should API Return Nested JSON Objects?

Another alternative (using HATEOAS). This is simple, mostly in practice you add a links tag in the json depending on your use of HATEOAS. http://api.example.com/games/1: { "id": 1, "title": "...
user avatar
  • 2,564
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 ...
user avatar
  • 17.3k
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 ...
user avatar
13 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 ...
user avatar
  • 1,022
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 ...
user avatar
13 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 ...
user avatar
  • 37.5k
12 votes
Accepted

Should I parse XML on the server or provide a proxy and let the browser parse it?

The proxy option is the easiest one to implement. You don't have any custom development to do, the only thing to do is to set up a proxy. It's also straightforward: there is no additional code to ...
user avatar
11 votes
Accepted

Why returning XML/JSON for API requests, can't we just directly process request and return the modified web page (HTML/CSS/JS)?

Because you can do many more things with real data besides display it in a web page. HTML is just a type of output that web browsers recognize, and it's not really useable as data in a meaningful way,...
user avatar
11 votes
Accepted

How deeply can a JSON object be nested?

There is no theoretical limit to how deep JSON objects can be nested, but there usually is a practical limit based on the decoder being used. For example, PHP's json_decode() has a default limit of ...
user avatar
  • 236
11 votes

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

Both [{"author": "Dan Brown", "isbn": "123456", "title": "Digital Fortress"},{"author": "JK Rowling", "isbn": "234567", "title": "Harry Potter and the Chamber of Secrets"}] and { "list": [{"...
user avatar
  • 3,418
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 ...
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 ...
user avatar
  • 37.5k
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 ...
user avatar
  • 9,007
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 ...
user avatar

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