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

  • Home
  • SEARCH
  • 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 6321981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:14:52+00:00 2026-05-24T16:14:52+00:00

I have a URL http://myapp.com/get_data that returns an application/json Content-Type . When I browse

  • 0

I have a URL http://myapp.com/get_data that returns an application/json Content-Type. When I browse to that URL, I’d get a plain-text JSON array in my browser window

[[key, value],
 [key, value],
 [key, value],
 ...]

I also have a JavaScript function that expects data to be in JSON array format

function process_data() {
  var data = // give me more data in JSON array format...
}

How do I make my JavaScript browse to http://myapp.com/get_data and assign the resulting JSON array into the data variable inside process_data()?

I’m new to JavaScript (coming from a Python background) and I would appreciate if you can suggest solutions that use the core JavaScript library. Solutions using other libraries are welcome also, preferably those that are considered best-practice.

UPDATE

It appears I wasn’t clear on my question. Let me provide an example from Python. After doing the necessary imports, I can do something like

url = "http://myapp.com/get_data"
page = urllib2.urlopen(url)
page_source = page.read()

This time, page_source is already a Python str object that I can easily play with, assign to other variables, etc. If I could mix Python and JavaScript together, for the context of this question, I want to do something like

function process_data() {
  url = "http://myapp.com/get_data"
  page = urllib2.urlopen(url)
  page_source = page.read()
  var data = convert_str_to_JSON(page_source)
}

Of course that was just an ugly mishmash of a code, but I hope it conveys what I’m trying to get at:

  1. JavaScript will GET a URL.
  2. Read the source.
  3. Interpret source as JSON.
  4. Assign it to a variable.
  • 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-24T16:14:54+00:00Added an answer on May 24, 2026 at 4:14 pm

    Newer browser support JSON parsing natively.

    You can say JSON.parse('json data'). For older browsers (such as IE 7 or 6), you can use this library: https://github.com/douglascrockford/JSON-js

    Use json2.js from above library. It checks if native browser implementation is present, if not, adds it.

    Do not use eval (as eval is evil)!

    Update: To get the ‘json data’, use this:

    var jsonObject = {}; 
    var xhr = new XMLHttpRequest();
    xhr.open( "GET", url, true );      // true makes this call asynchronous
    xhr.onreadystatechange = function () {    // need eventhandler since our call is async
         if ( xhr.readyState == 4 && xhr.status == 200 ) {  // check for success
            jsonObject = JSON.parse( xhr.responseText );
         }
    };
    xhr.send(null);
    

    Also, I would suggest reading this article for cross browser issues and implementation of XMLHttpRequest object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take a very simple case as an example, say I have this URL: http://www.example.com/65167.html
I have a base URL : http://my.server.com/folder/directory/sample And a relative one : ../../other/path How
If I have a URL (eg. http://www.foo.com/alink.pl?page=2 ), I want to determine if I
I have a page that is accessed via a URL like this: http://power-coder.net/Test/something.php?id=3#Page1 I
I have an http request that worked as http://blah.com and now I have been
In Kohana/CodeIgniter, I can have a URL in this form: http://www.name.tld/controller_name/method_name/parameter_1/parameter_2/parameter_3 ... And then
I have to check some code and run it. I have the URL: svn+ssh://myuser@www.myclient.com/home/svn/project/trunk
I have a long URL with tons of parameters that I want to open
I have a Django application being served of (say) example.com . It contains a
I'm using .NET MVC 2 If an incoming request contains the URL: http://something.com/1234 where

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.