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 8840929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:35:01+00:00 2026-06-14T10:35:01+00:00

Im trying to loop through a json file and pick out every episode, but

  • 0

Im trying to loop through a json file and pick out every episode, but I’m confused that my loop only output the first current_episode, much appreciated if anyone can check my problem!

app.get('/episodes', function(req, res){
    fs.readFile('channels.json', 'utf8', function (err, data) {
        var jsondata = JSON.parse(data);
        for (var i=0; i<jsondata.channels.length; i++){
            var myChannel = jsondata.channels[i].current_episode;
            res.send(myChannel);
        }
    })
}); 

My json data:

{
  "total": 70,
  "request_uri": "\/channels\/",
  "channels": [
    {
      "channel_id": 42,
      "current_episode": [
        {
          "id": 126248,
          "title": "Spanarna",
        }
      ]
    },
    {
      "channel_id": 43,
      "current_episode": [
        {
          "id": 126255,
          "title": "Beck: I stormens \u00f6ga",
        }
      ]
    },
............
}
  • 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-06-14T10:35:02+00:00Added an answer on June 14, 2026 at 10:35 am

    res.send writes the data and ends the request. Try this instead:

    app.get('/episodes', function(req, res){
        fs.readFile('channels.json', 'utf8', function (err, data) {
            var jsondata = JSON.parse(data);
            res.writeHead(200, {'Content-Type': 'text/plain'});
            for (var i=0; i<jsondata.channels.length; i++){
                var myChannel = jsondata.channels[i].current_episode;
                res.write(JSON.stringify(myChannel));
            }
            res.end();
        })
    }); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through this external JSON file(locally stored), but I cannot
I'm trying to loop through a json file and retrieve the title of each
Hi I am trying to loop through a json file like so: $.each(data.playlists.playlist, function(i,
I'm just learning json. I'm trying to loop through an array, but the length
I'm trying to loop through a number of items, and create a json object.
I'm trying to loop through the results from the Last.fm API but it's not
I am trying to loop through a vectors elements and trying to find out
I am trying to loop through each line in a file and find and
I'm trying to loop through a text file with a list of urls and
Im trying to loop through a json files' object array to access its variables'

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.