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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:51:05+00:00 2026-06-18T01:51:05+00:00

My API responds my call with the following JSON structure: [ { order: {

  • 0

My API responds my call with the following JSON structure:

[
    {
        "order": {
            "total": "240.0",
            "completed_at": 1358432545000
        }
    },
    {
        "order": {
            "total": "720.0",
            "completed_at": 1359474090000
        }
    }
]

However, I want this JSON to be structured like this in order to use my data in Flot Graphs:

   {
        "label":"Order",
        "dataBar":[
            [
                1358432545000,
                240.0
            ],
            [
                1325635200000 ,
                720.0
            ]
        ]
    }

I’ve tried the following code, but it returns all data with comma separated, without ‘[‘ and ‘]’

var flotData = $.map(API_Response, function(i){ return [i.order.completed_at, parseInt(i.order.total)] });

How should I do that?

  • 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-18T01:51:06+00:00Added an answer on June 18, 2026 at 1:51 am

    You can do this:

    var data2 = {
        label: 'Order',
        dataBar: data.map(function(v){return [
             v.order.completed_at,
             parseFloat(v.order.total)
        ]})
    };
    

    Demonstration (open the console to see data2)

    But please note there is nothing that can be called a “JSON structure” or a “JSON object”.

    What you have is a plain JavaScript object, even if it was sent to your browser encoded in JSON.


    Now supposing you don’t know the property of your object is called order, then you can do it with

    var label;
    for (var k in data[0]) {
       label = k[0].toUpperCase()+k.slice(1);
       break;
    }
    var data2 = {
        label: label,
        dataBar: data.map(function(v){return [
             v[k].completed_at,
             parseFloat(v[k].total)
        ]})
    };
    

    (It would be cleaner without support for IE 8, as I could have used Object.keys.)

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

Sidebar

Related Questions

I'm attempting to build a tree like structure with one main json call that
I am creating an API using Django. Every view responds in JSON. I would
I have an ajax call to fetch information from Flickr API which returns JSON
I have put together an API that responds to a POST request by putting
I make a call to FB graph api using FB IOS and handle the
response = Typhoeus::Request.get(http://localhost:3000/api/api_email/#{@api_id}.json) JSON.parse(response.body) The response is a JSON object but I get an
I'm building a publication in Ruby/Sinatra which responds to a GET call (from the
My Rails app needs to make a call to a partner's RESTful API for
I'm trying to access the Basecamp API through Rails, but it responds with a
A consumer is trying to call my REST API from client-side code (Javascript /

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.