Questions tagged [json]

JSON (JavaScript Object Notation) is a serializable data interchange format intended to be machine and human readable. Do not use this tag for native JavaScript objects or JavaScript object literals. Before you ask a question, validate your JSON using a JSON validator such as JSONLint (https://jsonlint.com).

Filter by
Sorted by
Tagged with
11099votes
37answers
3.4mviews

What is the correct JSON content type?

I've been messing around with JSON for some time, just pushing it out as text and it hasn't hurt anybody (that I know of), but I'd like to start doing things properly. I have seen so many purported &...
user avatar
  • 226k
8833votes
57answers
3.1mviews

Can comments be used in JSON?

Can I use comments inside a JSON file? If so, how?
user avatar
4329votes
8answers
570kviews

Why does Google prepend while(1); to their JSON responses?

Why does Google prepend while(1); to their (private) JSON responses? For example, here's a response while turning a calendar on and off in Google Calendar: while (1); [ ['u', [ ['smsSentFlag', ...
user avatar
  • 40.9k
3471votes
30answers
3.8mviews

How do I POST JSON data with cURL?

I use Ubuntu and installed cURL on it. I want to test my Spring REST application with cURL. I wrote my POST code at the Java side. However, I want to test it with cURL. I am trying to post a JSON data....
user avatar
  • 68.9k
3421votes
59answers
1.5mviews

How can I pretty-print JSON in a shell script?

Is there a (Unix) shell script to format JSON in human-readable form? Basically, I want it to transform the following: { "foo": "lorem", "bar": "ipsum" } ... ...
3012votes
28answers
1.4mviews

pretty-print JSON using JavaScript

How can I display JSON in an easy-to-read (for human readers) format? I'm looking primarily for indentation and whitespace, with perhaps even colors / font-styles / etc.
user avatar
  • 61.7k
2338votes
10answers
557kviews

What is JSONP, and why was it created?

I understand JSON, but not JSONP. Wikipedia's document on JSON is (was) the top search result for JSONP. It says this: JSONP or "JSON with padding" is a JSON extension wherein a prefix is specified ...
user avatar
  • 184k
2105votes
41answers
778kviews

How do I format a Microsoft JSON date?

I'm taking my first crack at Ajax with jQuery. I'm getting my data onto my page, but I'm having some trouble with the JSON data that is returned for Date data types. Basically, I'm getting a string ...
1734votes
16answers
2.0mviews

Parse JSON in JavaScript? [duplicate]

I want to parse a JSON string in JavaScript. The response is something like var response = '{"result":true,"count":1}'; How can I get the values result and count from this?
user avatar
1717votes
59answers
1.1mviews

Convert form data to JavaScript object with jQuery

How do I convert all elements of my form to a JavaScript object? I'd like to have some way of automatically building a JavaScript object from my form, without having to loop over each element. I do ...
1580votes
14answers
1.7mviews

How to prettyprint a JSON file?

I have a JSON file that is a mess that I want to prettyprint. What's the easiest way to do this in Python? I know PrettyPrint takes an "object", which I think can be a file, but I don't know how to ...
user avatar
  • 20.7k
1511votes
9answers
2.7mviews

Why can't Python parse this JSON data? [closed]

I have this JSON in a file: { "maps": [ { "id": "blabla", "iscategorical": "0" }, { &...
user avatar
  • 25.7k
1452votes
14answers
2.0mviews

How do I write JSON data to a file?

I have JSON data stored in the variable data. I want to write this to a text file for testing so I don't have to grab the data from the server each time. Currently, I am trying this: obj = open('...
user avatar
  • 21.8k
1441votes
27answers
1.4mviews

Safely turning a JSON string into an object

Given a string of JSON data, how can I safely turn that string into a JavaScript object? Obviously I can do this unsafely with something like: var obj = eval("(" + json + ')'); but that leaves me ...
user avatar
1382votes
15answers
1.5mviews

What is the "right" JSON date format?

I've seen so many different standards for the JSON date format: "\"\\/Date(1335205592410)\\/\"" .NET JavaScriptSerializer "\"\\/Date(1335205592410-0500)\\/\"" .NET ...
user avatar
1325votes
27answers
1.7mviews

Convert JS object to JSON string

If I defined an object in JS with: var j={"name":"binchen"}; How can I convert the object to JSON? The output string should be: '{"name":"binchen"}'
user avatar
  • 57.6k
1322votes
74answers
1.4mviews

How to compare arrays in JavaScript?

I'd like to compare two arrays... ideally, efficiently. Nothing fancy, just true if they are identical, and false if not. Not surprisingly, the comparison operator doesn't seem to work. var a1 = [1,2,...
user avatar
1310votes
29answers
603kviews

JavaScriptSerializer - JSON serialization of enum as string

I have a class that contains an enum property, and upon serializing the object using JavaScriptSerializer, my json result contains the integer value of the enumeration rather than its string "...
user avatar
  • 53.5k
1241votes
36answers
2.1mviews

How to parse JSON in Java

I have the following JSON text. How can I parse it to get the values of pageName, pagePic, post_id, etc.? { "pageInfo": { "pageName": "abc", ...
user avatar
1229votes
11answers
912kviews

Serializing to JSON in jQuery [duplicate]

I need to serialize an object to JSON. I'm using jQuery. Is there a "standard" way to do this? My specific situation: I have an array defined as shown below: var countries = new Array(); countries[0]...
user avatar
  • 49.5k
1220votes
29answers
920kviews

How do I get ASP.NET Web API to return JSON instead of XML using Chrome?

Using the newer ASP.NET Web API, in Chrome I am seeing XML - how can I change it to request JSON so I can view it in the browser? I do believe it is just part of the request headers, am I correct in ...
user avatar
  • 33k
1184votes
23answers
1.1mviews

How to reformat JSON in Notepad++?

I need Notepad++ to take a json string from this {"menu": {"id": "file","value": "File","popup": {"menuitem": [{"value": "New", "onclick": "CreateNewDoc()"},{"value": "Open", "onclick": "OpenDoc()"},{...
user avatar
  • 20.7k
1143votes
36answers
1.1mviews

How to make a class JSON serializable

How to make a Python class serializable? A simple class: class FileItem: def __init__(self, fname): self.fname = fname What should I do to be able to get output of: >>> ...
user avatar
  • 17k
1137votes
15answers
1.8mviews

How do I turn a C# object into a JSON string in .NET?

I have classes like these: class MyDate { int year, month, day; } class Lad { string firstName; string lastName; MyDate dateOfBirth; } And I would like to turn a Lad object into a ...
user avatar
  • 12.9k
1122votes
41answers
1.4mviews

Parsing JSON with Unix tools

I'm trying to parse JSON returned from a curl request, like so: curl 'http://twitter.com/users/username.json' | sed -e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; ...
user avatar
  • 12.5k
1112votes
30answers
956kviews

Deserialize JSON into C# dynamic object?

Is there a way to deserialize JSON content into a C# dynamic type? It would be nice to skip creating a bunch of classes in order to use the DataContractJsonSerializer.
user avatar
  • 15.6k
1098votes
33answers
830kviews

How to overcome "datetime.datetime not JSON serializable"?

I have a basic dict as follows: sample = {} sample['title'] = "String" sample['somedate'] = somedatetimehere When I try to do jsonify(sample) I get: TypeError: datetime.datetime(2012, 8, 8, 21, 46, ...
user avatar
  • 50.3k
1053votes
19answers
1.3mviews

Returning JSON from a PHP Script

I want to return JSON from a PHP script. Do I just echo the result? Do I have to set the Content-Type header?
user avatar
  • 10.8k
1015votes
31answers
1.0mviews

How to parse JSON using Node.js? [closed]

How should I parse JSON using Node.js? Is there some module which will validate and parse JSON securely?
user avatar
1006votes
14answers
641kviews

Use of PUT vs PATCH methods in REST API real life scenarios

First of all, some definitions: PUT is defined in Section 9.6 RFC 2616: The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an ...
user avatar

15 30 50 per page
1
2 3 4 5
11244