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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:41:48+00:00 2026-06-18T08:41:48+00:00

i have a json data and trying to parse it with d3.json function.The format

  • 0

i have a json data and trying to parse it with d3.json function.The format of the data is like this .

{
"StoreVisitGraphCount": {
    "list": {
        "count": 23,
        "date": "01-2013"
    },
    "parameters": {
        "format": "m-Y",
        "point": 10,
        "type": "mo"
    }
   }
}

i am trying to parse it with the following function

d3.json("http://localhost:8080/data-  services/rest/storeVisitsGraph/20120101,20131231,-1", function(error, data) {
data.StoreVisitGraphCount.list.forEach(function(d) {
d.date = parseDate(d.date);
d.count = +d.count;
});

its showing an error say “Uncaught TypeError: Object # has no method ‘forEach'”
but after modifying the json data to

 {
"StoreVisitGraphCount": {
    "list": [{
        "count": 23,
        "date": "01-2013"
    }],
    "parameters": {
        "format": "m-Y",
        "point": 10,
        "type": "mo"
    }
   }
}

making the list an array .. it parsed sucessfully showing no error..
as when there is only one data in list array the rest creates the json like the first format but when there is more than one list data
it creates the json like second format… how to solve or write function in d3.js so that it can parse the first format too …

  • 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-18T08:41:49+00:00Added an answer on June 18, 2026 at 8:41 am

    If you want to deal with both the data formats, the most straight forward way to do it is checking whether the data.StoreVisitGraphCount.list is an Array or an Object. Taking a cure from the question: How to check if a JSON response element is an array? , the most reliable way to do it is:

    function isArray(what) {
        return Object.prototype.toString.call(what) === '[object Array]';
    }
    

    Then your code would read:

    d3.json(..., function(error, data) {
      if (!isArray(data.StoreVisitGraphCount.list)) {
        data.StoreVisitGraphCount.list = [ data.StoreVisitGraphCount.list ];
      }
    
      data.StoreVisitGraphCount.list.forEach(function(d) {
        d.date = parseDate(d.date);
        d.count = +d.count;
      });
    });
    

    However, that is not a very consistent API design. If the API is in your control (you are running the service from localhost), then consider changing it to be consistent and return a list in every case.

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

Sidebar

Related Questions

I have a text file that contains cached data in JSON format. I'm trying
i have json data like this {GetStudentDetails: {TotalCount:5, RootResults:[ {city:West Chester,country:USA,state:PA ,student_id:100}, {city:Philly,country:USA,state:PA,student_id:101}, {city:Buffalo,country:USA,state:NY,student_id:102},
I have a JSON data like this: { hello: { first:firstvalue, second:secondvalue }, hello2:
I have a web service and I'm trying to get data by JSON. if
Let's say i have this json data. How to transform the tags to a
I have been trying to access/parse the message object found in the JSON results
I am trying to retrieve data with JSON from my database and parse them
I have the following JSON: {COLUMNS:[ID,FIRSTNAME],DATA:[[1,Steve],[2,Jim],[3,Bill],[4,Tony]]} I am trying to write some jQuery that
I am trying to parse the following JSON data, but it seems that it
I am trying to parse a json file using jquery getJson. I have no

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.