All Questions

Tagged with
Filter by
Sorted by
Tagged with
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
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
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
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
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
616votes
15answers
720kviews

Return JSON response from Flask view

I have a function that analyzes a CSV file with Pandas and produces a dict with summary information. I want to return the results as a response from a Flask view. How do I return a JSON response? @...
user avatar
  • 6,415
522votes
17answers
629kviews

Creating a JSON response using Django and Python

I'm trying to convert a server side Ajax response script into a Django HttpResponse, but apparently it's not working. This is the server-side script: /* RECEIVE VALUE */ $validateValue=$_POST['...
user avatar
  • 13.6k
472votes
4answers
844kviews

Convert JSON string to dict using Python

I'm a little bit confused with JSON in Python. To me, it seems like a dictionary, and for that reason I'm trying to do that: { "glossary": { "title": "example glossary", "...
user avatar
  • 10.5k
459votes
23answers
1.4mviews

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I am getting error Expecting value: line 1 column 1 (char 0) when trying to decode JSON. The URL I use for the API call works fine in the browser, but gives this error when done through a curl request....
user avatar
  • 7,490
457votes
6answers
160kviews

Can I get JSON to load into an OrderedDict?

Ok so I can use an OrderedDict in json.dump. That is, an OrderedDict can be used as an input to JSON. But can it be used as an output? If so how? In my case I'd like to load into an OrderedDict so I ...
user avatar
451votes
6answers
688kviews

Converting dictionary to JSON

r = {'is_claimed': 'True', 'rating': 3.5} r = json.dumps(r) file.write(str(r['rating'])) I am not able to access my data in the JSON. What am I doing wrong? TypeError: string indices must be ...
user avatar
  • 6,498
450votes
12answers
688kviews

How to get POSTed JSON in Flask?

I'm trying to build a simple API using Flask, in which I now want to read some POSTed JSON. I do the POST with the Postman Chrome extension, and the JSON I POST is simply {"text":"lalala"}. I try to ...
user avatar
  • 43.9k
429votes
7answers
848kviews

Reading JSON from a file?

I am getting a bit of headache just because a simple looking, easy statement is throwing some errors in my face. I have a json file called strings.json like this: "strings": [{"-name&...
user avatar
  • 4,765

15 30 50 per page
1
2 3 4 5
1962