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
961votes
9answers
841kviews

How to use Jackson to deserialise an array of objects

The Jackson data binding documentation indicates that Jackson supports deserialising "Arrays of all supported types" but I can't figure out the exact syntax for this. For a single object I would do ...
user avatar
910votes
9answers
1.3mviews

How to POST JSON data with Python Requests?

I need to POST a JSON from a client to a server. I'm using Python 2.7.1 and simplejson. The client is using Requests. The server is CherryPy. I can GET a hard-coded JSON from the server (code not ...
user avatar
  • 15.6k
910votes
11answers
780kviews

Posting a File and Associated Data to a RESTful WebService preferably as JSON

This is probably going to be a stupid question but I'm having one of those nights. In an application I am developing RESTful API and we want the client to send data as JSON. Part of this application ...
user avatar
  • 33.3k
884votes
10answers
951kviews

Are multi-line strings allowed in JSON?

Is it possible to have multi-line strings in JSON? It's mostly for visual comfort so I suppose I can just turn word wrap on in my editor, but I'm just kinda curious. I'm writing some data files in ...
user avatar
  • 9,001
880votes
15answers
417kviews

Ajax request returns 200 OK, but an error event is fired instead of success

I have implemented an Ajax request on my website, and I am calling the endpoint from a webpage. It always returns 200 OK, but jQuery executes the error event. I tried a lot of things, but I could not ...
user avatar
865votes
14answers
415kviews

What is the difference between YAML and JSON?

What are the differences between YAML and JSON, specifically considering the following things? Performance (encode/decode time) Memory consumption Expression clarity Library availability, ease of use ...
user avatar
  • 37.9k
848votes
45answers
1.0mviews

Jackson with JSON: Unrecognized field, not marked as ignorable

I need to convert a certain JSON string to a Java object. I am using Jackson for JSON handling. I have no control over the input JSON (I read from a web service). This is my input JSON: {"wrapper":[{"...
user avatar
  • 8,561
825votes
16answers
1.2mviews

Fetch: POST JSON data

I'm trying to POST a JSON object using fetch. From what I can understand, I need to attach a stringified object to the body of the request, e.g.: fetch("/echo/json/", { headers: { '...
user avatar
  • 22.6k
820votes
18answers
660kviews

Is there any standard for JSON API response format?

Do standards or best practices exist for structuring JSON responses from an API? Obviously, every application's data is different, so that much I'm not concerned with, but rather the "response ...
user avatar
  • 26.2k
810votes
29answers
849kviews

How can I print a circular structure in a JSON-like format?

I have a big object I want to convert to JSON and send. However it has circular structure. I want to toss whatever circular references exist and send whatever can be stringified. How do I do that? ...
user avatar
  • 49k
785votes
22answers
820kviews

How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?

I have a simple key/value list in JSON being sent back to ASP.NET via POST. Example: { "key1": "value1", "key2": "value2"} I AM NOT TRYING TO DESERIALIZE INTO STRONGLY-TYPED .NET OBJECTS I simply ...
user avatar
773votes
12answers
654kviews

Using Node.JS, how do I read a JSON file into (server) memory?

Background I am doing some experimentation with Node.js and would like to read a JSON object, either from a text file or a .js file (which is better??) into memory so that I can access that object ...
user avatar
  • 22.2k
716votes
19answers
350kviews

How to "pretty" format JSON output in Ruby on Rails

I would like my JSON output in Ruby on Rails to be "pretty" or nicely formatted. Right now, I call to_json and my JSON is all on one line. At times this can be difficult to see if there is a ...
user avatar
711votes
26answers
699kviews

Pretty-Printing JSON with PHP

I'm building a PHP script that feeds JSON data to another script. My script builds data into a large associative array, and then outputs the data using json_encode. Here is an example script: $data = ...
user avatar
  • 19.7k
710votes
18answers
610kviews

Binary Data in JSON String. Something better than Base64

The JSON format natively doesn't support binary data. The binary data has to be escaped so that it can be placed into a string element (i.e. zero or more Unicode chars in double quotes using backslash ...
user avatar
  • 33.2k
707votes
30answers
693kviews

Can I set an unlimited length for maxJsonLength in web.config?

I am using the autocomplete feature of jQuery. When I try to retrieve the list of more then 17000 records (each won't have more than 10 char length), it's exceeding the length and throws the error: ...
user avatar
  • 57.5k
700votes
12answers
515kviews

Saving utf-8 texts with json.dumps as UTF8, not as \u escape sequence

Sample code: >>> import json >>> json_string = json.dumps("ברי צקלה") >>> print(json_string) "\u05d1\u05e8\u05d9 \u05e6\u05e7\u05dc\u05d4" The problem: ...
user avatar
697votes
25answers
798kviews

How to check if a string is a valid JSON string?

isJsonString('{ "Id": 1, "Name": "Coke" }') should be true and isJsonString('foo') isJsonString('<div>foo</div>') should be false. I'm looking for a ...
user avatar
  • 10.6k
691votes
12answers
592kviews

Ignoring new fields on JSON objects using Jackson [duplicate]

I'm using Jackson JSON library to convert some JSON objects to POJO classes on an android application. The problem is, the JSON objects might change and have new fields added while the application is ...
user avatar
650votes
16answers
853kviews

Cannot use object of type stdClass as array?

I get a strange error using json_decode(). It decode correctly the data (I saw it using print_r), but when I try to access to info inside the array I get: Fatal error: Cannot use object of type ...
user avatar
  • 6,509

15 30 50 per page
1
2 3 4 5
6746