Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7419763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:07:39+00:00 2026-05-29T08:07:39+00:00

A project for class involves parsing Twitter JSON data. I’m getting the data and

  • 0

A project for class involves parsing Twitter JSON data. I’m getting the data and setting it to the file without much trouble, but it’s all in one line. This is fine for the data manipulation I’m trying to do, but the file is ridiculously hard to read and I can’t examine it very well, making the code writing for the data manipulation part very difficult.

Does anyone know how to do that from within Python (i.e. not using the command line tool, which I can’t get to work)? Here’s my code so far:

header, output = client.request(twitterRequest, method="GET", body=None,
                            headers=None, force_auth_header=True)

# now write output to a file
twitterDataFile = open("twitterData.json", "wb")
# magic happens here to make it pretty-printed
twitterDataFile.write(output)
twitterDataFile.close()

Note I appreciate people pointing me to simplejson documentation and such, but as I have stated, I have already looked at that and continue to need assistance. A truly helpful reply will be more detailed and explanatory than the examples found there. Thanks

Also:
Trying this in the windows command line:

more twitterData.json | python -mjson.tool > twitterData-pretty.json

results in this:

Invalid control character at: line 1 column 65535 (char 65535)

I’d give you the data I’m using, but it’s very large and you’ve already seen the code I used to make the file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:07:40+00:00Added an answer on May 29, 2026 at 8:07 am

    You should use the optional argument indent.

    header, output = client.request(twitterRequest, method="GET", body=None,
                                headers=None, force_auth_header=True)
    
    # now write output to a file
    with open("twitterData.json", "w") as twitterDataFile:
        # magic happens here to make it pretty-printed
        twitterDataFile.write(
            simplejson.dumps(simplejson.loads(output), indent=4, sort_keys=True)
        )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class named project with the following data members. class Project {
I have a project that involves recording data from a device directly into a
I am working on a project which basically involves parsing and storing information about
A class project involves sorting an array of strings, with each string containing an
I am trying to work on a project which involves running/executing the java file
I'm working on a (rather horrible) project that involves importing a C++ class hierarchy
I am using C# and developing a winform application. I have a project class
class Project(models.Model): categories = models.ManyToManyField(Category) class Category(models.Model): name = models.CharField() now, i make some
I have a Project model similar to: class Project(models.Model): ... lead_analyst=models.ForeignKey(User, related_name='lead_analyst') ... I
Given the following model: class Project(models.Model): project_name = models.CharField(max_length=255) abstract = models.TextField(blank=True, null=True) full_description

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.