Questions tagged [json]

JSON (JavaScript Object Notation) aka the Fat Free Alternative to XML is a lightweight data exchange format inspired by JavaScript object literals. It is often used with JavaScript, Ajax, and RESTful web services but is completely language independent.

JSON (JavaScript Object Notation) is a lightweight data exchange format and is often used with and RESTful .

JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

JSON is built on two structures:

  • A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
  • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

These are universal data structures. Virtually all modern programming languages support them in one form or another. It makes sense that a data format that is interchangeable with programming languages is also based on these structures.

Its syntax was inspired by a subset of the JavaScript object literal notation.

{
    "names": { "first": "John", "last": "Doe" },
    "languages": [ "javascript", "python", "lisp" ]
}

JSON is not the same thing as JavaScript object literals. Rather, JSON is a common technique to serialize from and deserialize to JavaScript's (and other languages') objects.

Useful links:

Browser Addons

355 questions
85
votes
7 answers

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

I've always used JSON files for configuration of my applications. I started using them from when I coded a lot of Java, and now I'm working mainly on server-side and data science Python development and am not sure if JSON is the right way to go any…
84
votes
12 answers

Can we replace XML with JSON entirely?

I'm sure lots of developers are familiar with XML and JSON, and they've used both of them. Thus no point in explaining what they are, and what is their purpose, even in brief. If we try to map their concepts, we can say (correct me if I'm…
Saeed Neamati
  • 18,142
  • 23
  • 87
  • 125
69
votes
6 answers

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

Assume we have resources like this, book: type: object properties: author: {type: string} isbn: {type: string} title: {type: string} books: type: array items: book So, when someone makes a GET on the books…
borncrusader
  • 791
  • 1
  • 5
  • 4
62
votes
1 answer

null vs missing key in REST API Response

Say in my application, some users give us their last name, and others do not. In a REST API response, which body is preferred: With a "null" value: {"firstName": "Bob", "lastName": null} Or just a missing key: {"firstName": "Bob"}
jtmarmon
  • 958
  • 1
  • 8
  • 12
60
votes
14 answers

RESTful API design. What should I return if there are no rows?

I'm currently coding an API for a social network with the Slim Framework. My question is: What are the best practices when there are no rows to return in the json structure? Lets say that this call /v1/get/movies returns 2 rows from the table movie…
Andres SK
  • 703
  • 1
  • 5
  • 7
54
votes
2 answers

REST API - Should API Return Nested JSON Objects?

When it comes to JSON APIs is it good practice to flatten out responses and avoid nested JSON objects? As an example lets say we have an API similar to IMDb but for video games. There are a couple entities, Game, Platform, ESRBRating, and…
greyfox
  • 869
  • 1
  • 8
  • 11
41
votes
4 answers

What JSON structure to use for key value pairs?

What JSON format is a better choice for key value pairs and why? [{"key1": "value1"}, {"key2": "value2"}] Or: [{"Name": "key1", "Value": "value1"}, {"Name": "key2", "Value": "value2"}] Or: {"key1": "value1", "key2": "value2"} The first variant…
boot4life
  • 665
  • 1
  • 6
  • 8
36
votes
2 answers

How to represent a set in JSON?

JSON supports the following data structures (Java equivalents): Scalar, Array/List, and Map. A Set is not supported out-of-the-box in JSON. I thought about several ways to represent a set in JSON: [1] - As a list However, a list has its own…
Ron Klein
  • 671
  • 2
  • 6
  • 13
34
votes
3 answers

JSON Web Token - why is the payload public?

I can't understand the reasoning for making the claims/payload of a JWT publicly visible after base64 decoding it. Why? It seems like it'd be much more useful to have it encrypted with the secret. Can someone explain why, or in what situation,…
ineedhelp
  • 451
  • 1
  • 4
  • 5
34
votes
3 answers

Is it OK to return HTML from a JSON API?

On my current project I am responsible for the implementation of a service which involves the consumption of newly created RESTful APIs, documented as solely supporting JSON. The client consistently makes requests with the accept header of…
phillip.darley
  • 443
  • 1
  • 4
  • 7
30
votes
6 answers

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

I am working on a project where I am trying to decide between using a standard SQL relational database or JSON objects to store data about an event or activity. The project will store data on multiple event types so I have decided to just describe…
zgall1
  • 343
  • 1
  • 3
  • 7
25
votes
2 answers

Logging in JSON Effect on Performance

I see more and more articles about logging in JSON. You can also find one on NodeJS blog. Why does everyone like it so much? I can only see more operations getting involved: A couple new objects being created. Stringifying objects, which either…
Pijusn
  • 987
  • 1
  • 10
  • 16
24
votes
4 answers

What is the need of Odata when I have JSON?

I am trying to understand the point of Odata and when it would make sense. Right now how I work is I use ASP.NET and MVC/WebApi controller to serialize/deserialize objects into JSON and have javascript do something with it. From what I can tell the…
punkouter
  • 1,123
  • 2
  • 10
  • 18
23
votes
1 answer

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

I'm working in C# and doing some communication between 2 apps I'm writing. I have come to like the Web API and JSON. Now I am at the point where I am writing a routine to send a record between the two servers that includes some text data and a file.…
Ian
  • 395
  • 1
  • 2
  • 9
20
votes
1 answer

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

This had probably started way back when Microsoft created ASP.NET Web API library, at least that's when I remember it if I am not mistaken. Anyway, since then, its HTTP packages started depending on Newtonsoft.Json library for data (de)serialization…
paulius_l
  • 319
  • 1
  • 3
  • 7
1
2 3
23 24