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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:52:49+00:00 2026-06-06T12:52:49+00:00

What would be the easiest way to convert the following key->value object array to

  • 0

What would be the easiest way to convert the following key->value object “array” to a proper “JSON” style object? Example below would be converting input into graph.

var input = {
    "graph.default.seriesColor" : ["#cccccc", "#3c3c3c"],
    "graph.default.stackSeries" : false,
    "graph.default.title.text" : "Hello!",
    "graph.default.title.show" : false,
    "graph.default.axesDefaults.show" : true,
    "graph.default.axesDefaults.min" : 17,
    "graph.default.axesDefaults.max" : 20,
};

var graph = {
    default: {
        seriesColor: ["#cccccc", "#3c3c3c"],
        stackSeries: false,

        title: {
            text: "Hello!",
            show: false
        },

        axesDefault: {
            show: true,
            min: 17,
            max: 20
        }
    }
};

I considered using eval, however it quickly became complicated in a recursive way.

  • 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-06T12:52:51+00:00Added an answer on June 6, 2026 at 12:52 pm

    For some reason I really felt like writing you a function for this:

    function makeObj(input)
    {
        var output = {};
    
        for(var key in input)
        {
            var nodes = key.split('.'), dest = output;
    
            if(nodes.length < 1)
                continue;
    
            for(var i = 0; i < (nodes.length - 1); ++ i)
            {
                var node = nodes[i];
    
                dest = (dest[node] === undefined) ?
                            (dest[node] = {}) : dest[node];
            }
    
            dest[nodes[nodes.length - 1]] = input[key];
        }
    
        return output;
    }
    
    graph = makeObj(input);
    

    Obviously unlike an eval solution, this will only accept strings in the exact format you described (x.y.z).

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

Sidebar

Related Questions

Whats the easiest way to take a JSON or Array object and convert it
What would be the easiest way to update a HTML tag with the following
What's the quickest and easiest way to convert my json, containing the data of
What would be the easiest way to convert a number to base 2 (in
What's the easiest way to convert these requests: http://www.example.com/en/ http://www.example.com/en/index.php To: http://www.example.com/index.php?language_id=en There's various
I would like to ask what is the easiest and faster way to convert
What would be the easiest way to load a file containing JSON into a
I would like to know what is the easiest way to convert an int
What would be the easiest way to transform $('#my_element').css('backgroundColor') to object like this: {
What would be the easiest way of using commands in the code to programatically

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.