Steem Bounty : Nestify a flat JSON object by gokulnk

View this thread on steempeak.com
· @gokulnk · (edited)
$5.60
Steem Bounty : Nestify a flat JSON object
I recently had a requirement in a project where I had to convert a flat JSON object into a nested JSON object. Instead of explaining the problem statement I will share a set of input and output arrays so that the requirement becomes clear. 

![javascript.jpg](https://cdn.steemitimages.com/DQmdfyrfkJwrrHW79XHYRUyjwNumaikhgKH83hzGaJsSh19/javascript.jpg)


```javascript
const input1 = [{
        pos: 1,
        text: 'Andy'
    },
    {
        pos: 1,
        text: 'Harry'
    },
    {
        pos: 2,
        text: 'David'
    },
    {
        pos: 1,
        text: 'Lisa'
    },
];
const output1 = [{
        pos: 1,
        text: 'Andy'
    },
    {
        pos: 1,
        text: 'Harry',
        children: [{
            pos: 2,
            text: 'David'
        }]
    },
    {
        pos: 1,
        text: 'Lisa'
    }
];

const input2 = [{
        pos: 1,
        text: 'Andy'
    },
    {
        pos: 1,
        text: 'Harry'
    },
    {
        pos: 2,
        text: 'David'
    },
    {
        pos: 2,
        text: 'Edger'
    },
    {
        pos: 1,
        text: 'Lisa'
    },
];
const output2 = [{
        pos: 1,
        text: 'Andy'
    },
    {
        pos: 1,
        text: 'Harry',
        children: [{
                pos: 2,
                text: 'David'
            },
            {
                pos: 2,
                text: 'Edger'
            }
        ]
    },
    {
        pos: 1,
        text: 'Lisa'
    }
];

const input3 = [{
        pos: 1,
        text: 'Andy'
    },
    {
        pos: 1,
        text: 'Harry'
    },
    {
        pos: 2,
        text: 'David'
    },
    {
        pos: 3,
        text: 'Dexter'
    },
    {
        pos: 2,
        text: 'Edger'
    },
    {
        pos: 1,
        text: 'Lisa'
    },
];
const output3 = [{
        pos: 1,
        text: 'Andy'
    },
    {
        pos: 1,
        text: 'Harry',
        children: [{
                pos: 2,
                text: 'David',
                children: [{
                    pos: 3,
                    text: 'David'
                }]
            },
            {
                pos: 2,
                text: 'Edger'
            }
        ]
    },
    {
        pos: 1,
        text: 'Lisa'
    }
];
``` 

A comment explaining the approach along with a link to Github gist or code in comment will be appreciated. Bounties are handled by Steem Bounty
๐Ÿ‘  , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
post_id52,196,855
authorgokulnk
permlinknestify-a-flat-json-object
categoryjavascript
json_metadata"{"format": "markdown", "image": ["https://cdn.steemitimages.com/DQmdfyrfkJwrrHW79XHYRUyjwNumaikhgKH83hzGaJsSh19/javascript.jpg"], "app": "steemit/0.1", "tags": ["javascript", "development", "algorithm", "dev"]}"
created2018-06-08 11:08:18
last_update2018-06-13 08:41:12
depth0
children31
net_rshares2,327,402,837,806
last_payout2018-06-15 11:08:18
cashout_time1969-12-31 23:59:59
total_payout_value4.070 SBD
curator_payout_value1.531 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length2,380
author_reputation17,874,019,286,870
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries
0.
accountsteem-bounty
weight1,500
max_accepted_payout100,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (25)
@steem-bounty ·
Buonty added
@gokulnk has set 11.000 STEEM bounty on this post! ![logo_for-light-bg_1000.png](https://steemitimages.com/DQmdYbGNQCwrAsveg9Yv5YeRqCCzjCYhoavinDwYLqPN9mu/logo_for-light-bg_1000.png)   <br>  <b>What is a bounty exactly? </b> <p> A bounty is money sent to a post to be distributed to the users commenting on it. It provides a way to reward users directly and works in addition to the steem/sbd they receive from the blockchain. It works independently of SteemPower.</p>  <p>   You create a bounty by sending any amount of sbd/steem to @steem-bounty together with a post-url in the memo. </p> <b> How can I earn a bounty</b>   Users are then competing for the bounty by writing their answers to the post in comments that will achieve upvotes from the community and especially the bounty creator.   The money of the bounty gets distributed to all top level comments of the post at the same time when the post is paid out (7 Days after it was written). How much everyone gets depends on the votes the comments received. The sender of the bounties votes are weighted higher so that she decideds where 80% of the bounty money goes and all other votes determine the rest.</p>  <p> @steem-bounty does all of this for you automatically. You can use this service to automatically pay out a challenge, ask a hard question or simply to reward the people that interact with you.  </p>  <p> Read more about how it works, even in different languages [here](https://steemit.com/steem-bounty/@steem-bounty/how-to-create-a-bounty-in-several-languages). </p>
properties (22)
post_id52,197,020
authorsteem-bounty
permlinkre-nestify-a-flat-json-object-20180608t111018
categoryjavascript
json_metadata"{"percent_steem_dollars": 0, "allow_votes": false, "allow_curation_rewards": false, "max_accepted_payout": "0.000 SBD", "permlink": "nestify-a-flat-json-object", "author": "gokulnk"}"
created2018-06-08 11:10:18
last_update2018-06-08 11:10:18
depth1
children1
net_rshares0
last_payout2018-06-15 11:10:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length1,539
author_reputation168,095,294,179,951
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@steem-bounty ·
Bounty Payout
Congratulations to the following winner(s) of the bounty!
- @elleok has earned 0.086 STEEM. 0.075 STEEM from the creator of the bounty and 0.011 STEEM from the community!
- @jmhb85 has earned 0.076 STEEM. 0.075 STEEM from the creator of the bounty and 0.001 STEEM from the community!
- @tsnaks has earned 0.075 STEEM. 0.075 STEEM from the creator of the bounty and 0.001 STEEM from the community!
- @malloryblythe has earned 0.084 STEEM. 0.075 STEEM from the creator of the bounty and 0.010 STEEM from the community!
- @mow has earned 0.075 STEEM. 0.075 STEEM from the creator of the bounty and 0.000 STEEM from the community!
- @crypticat has earned 0.379 STEEM. 0.373 STEEM from the creator of the bounty and 0.006 STEEM from the community!
- @zorank has earned 0.075 STEEM. 0.075 STEEM from the creator of the bounty and 0.001 STEEM from the community!
- @fresteem has earned 0.306 STEEM. 0.298 STEEM from the creator of the bounty and 0.007 STEEM from the community!
- @sparkofphoenix has earned 0.091 STEEM. 0.075 STEEM from the creator of the bounty and 0.016 STEEM from the community!
- @mightypanda has earned 9.599 STEEM. 7.458 STEEM from the creator of the bounty and 2.142 STEEM from the community!
- @lanzjoseg has earned 0.001 STEEM. 0.000 STEEM from the creator of the bounty and 0.001 STEEM from the community!
- @adalhelm has earned 0.077 STEEM. 0.075 STEEM from the creator of the bounty and 0.002 STEEM from the community!
- @birapada has earned 0.075 STEEM. 0.075 STEEM from the creator of the bounty and 0.000 STEEM from the community!
- @soumon has earned 0.002 STEEM. 0.000 STEEM from the creator of the bounty and 0.002 STEEM from the community!
properties (22)
post_id53,097,838
authorsteem-bounty
permlinkre-re-nestify-a-flat-json-object-20180608t111018-20180615t110903
categoryjavascript
json_metadata"{"allow_curation_rewards": false, "allow_votes": false, "max_accepted_payout": "0.000 SBD", "percent_steem_dollars": 0, "permlink": "re-nestify-a-flat-json-object-20180608t111018", "author": "steem-bounty"}"
created2018-06-15 11:09:03
last_update2018-06-15 11:09:03
depth2
children0
net_rshares0
last_payout2018-06-22 11:09:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length1,668
author_reputation168,095,294,179,951
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@elleok · (edited)
$0.03
Just trying ro refresh my programming skills after a two year break. Sadly there are more questions for me than answers for you after trying a few minutes to help you out with this problem. 

Will follow this maybe someone got an explanation I do understand to.

Resteemed it for more exposure!
๐Ÿ‘  , , ,
properties (23)
post_id52,219,689
authorelleok
permlinkre-gokulnk-nestify-a-flat-json-object-20180608t144735755z
categoryjavascript
json_metadata"{"tags": ["javascript"], "app": "steemit/0.1"}"
created2018-06-08 14:47:36
last_update2018-06-08 14:48:18
depth1
children1
net_rshares12,971,536,606
last_payout2018-06-15 14:47:36
cashout_time1969-12-31 23:59:59
total_payout_value0.028 SBD
curator_payout_value0.005 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length294
author_reputation18,431,282,494,259
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (4)
@gokulnk ·
Thanks for the resteem.
properties (22)
post_id52,563,570
authorgokulnk
permlinkre-elleok-re-gokulnk-nestify-a-flat-json-object-20180611t053617064z
categoryjavascript
json_metadata"{"app": "steemit/0.1", "tags": ["javascript"]}"
created2018-06-11 05:36:09
last_update2018-06-11 05:36:09
depth2
children0
net_rshares0
last_payout2018-06-18 05:36:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length23
author_reputation17,874,019,286,870
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@jmhb85 ·
The data is obtained from any source: file, database, content, or other form. Then you will have to make sure to define where you will get that information and in agreement you will need to do one thing or another. For example, if it is from a database, the structure creates it with a server language. if it is for a series of content that the user enters, he would have to provide several form controls and the possibility of adding several records. then with javascript you iterate the records and you are adding the information to the json creating the necessary properties.
properties (22)
post_id52,231,290
authorjmhb85
permlinkre-gokulnk-nestify-a-flat-json-object-20180608t162839495z
categoryjavascript
json_metadata{}
created2018-06-08 16:28:39
last_update2018-06-08 16:28:39
depth1
children0
net_rshares0
last_payout2018-06-15 16:28:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length578
author_reputation6,726,323,919,212
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries
0.
accountsteem-bounty
weight1,500
max_accepted_payout100,000.000 SBD
percent_steem_dollars10,000
@tsnaks ·
Ok,
this is too much for my brain
properties (22)
post_id52,236,305
authortsnaks
permlinkre-gokulnk-nestify-a-flat-json-object-20180608t171607480z
categoryjavascript
json_metadata"{"tags": ["javascript"], "app": "steemit/0.1"}"
created2018-06-08 17:16:06
last_update2018-06-08 17:16:06
depth1
children1
net_rshares0
last_payout2018-06-15 17:16:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length33
author_reputation21,107,871,637,009
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@gokulnk ·
It is for many programming brains as well ;) But this is a good problem to solve. I have been lazy and posed a Gig. Ideally I would have liked to spend time on this and come out with a solution. Now I will atleast analyse the solutions provided.
properties (22)
post_id52,564,171
authorgokulnk
permlinkre-tsnaks-re-gokulnk-nestify-a-flat-json-object-20180611t054249872z
categoryjavascript
json_metadata"{"app": "steemit/0.1", "tags": ["javascript"]}"
created2018-06-11 05:42:48
last_update2018-06-11 05:42:48
depth2
children0
net_rshares0
last_payout2018-06-18 05:42:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length245
author_reputation17,874,019,286,870
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@malloryblythe ·
$0.03
Holy crap that's a huge bounty. I can't contribute anything here for lack of necessary skills, but good luck. (No, I'm not expecting an upvote here; just expressing my admiration.)
properties (22)
post_id52,255,843
authormalloryblythe
permlinkre-gokulnk-nestify-a-flat-json-object-20180608t203505353z
categoryjavascript
json_metadata"{"tags": ["javascript"], "app": "steemit/0.1"}"
created2018-06-08 20:35:06
last_update2018-06-08 20:35:06
depth1
children1
net_rshares0
last_payout2018-06-15 20:35:06
cashout_time1969-12-31 23:59:59
total_payout_value0.023 SBD
curator_payout_value0.005 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length180
author_reputation2,267,543,125,870
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@gokulnk ·
I wanted to give Steem Bounty a try. Looks like it can get things done. Based on the output of this gig, I am planning to publish more gigs :)
properties (22)
post_id52,565,262
authorgokulnk
permlinkre-malloryblythe-re-gokulnk-nestify-a-flat-json-object-20180611t055540251z
categoryjavascript
json_metadata"{"tags": ["javascript"], "app": "steemit/0.1"}"
created2018-06-11 05:55:30
last_update2018-06-11 05:55:30
depth2
children0
net_rshares0
last_payout2018-06-18 05:55:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length142
author_reputation17,874,019,286,870
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@m2nnari ·
Deivid vรตi Daweed?
properties (22)
post_id52,268,823
authorm2nnari
permlinkre-gokulnk-nestify-a-flat-json-object-20180608t230232273z
categoryjavascript
json_metadata"{"tags": ["javascript"], "app": "steemit/0.1"}"
created2018-06-08 23:02:30
last_update2018-06-08 23:02:30
depth1
children0
net_rshares0
last_payout2018-06-15 23:02:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length18
author_reputation1,929,992,207,692
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@crypticat · (edited)
$0.02
You want to convert your file from flat to nested, so here is a GitHub link as requested ๐Ÿ˜ธ good luck with your project!

https://github.com/joaonuno/flat-to-nested-js/blob/master/README.md
properties (22)
post_id52,283,163
authorcrypticat
permlinkre-gokulnk-nestify-a-flat-json-object-20180609t021244355z
categoryjavascript
json_metadata"{"links": ["https://github.com/joaonuno/flat-to-nested-js/blob/master/README.md"], "tags": ["javascript"], "app": "steemit/0.1"}"
created2018-06-09 02:12:45
last_update2018-06-09 02:14:45
depth1
children1
net_rshares0
last_payout2018-06-16 02:12:45
cashout_time1969-12-31 23:59:59
total_payout_value0.020 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length188
author_reputation121,774,275,823,341
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@gokulnk ·
This doesn't solve the problem in question directly. But it does solve one half of it. Thanks for the link.
properties (22)
post_id52,563,409
authorgokulnk
permlinkre-crypticat-re-gokulnk-nestify-a-flat-json-object-20180611t053450438z
categoryjavascript
json_metadata"{"app": "steemit/0.1", "tags": ["javascript"]}"
created2018-06-11 05:34:45
last_update2018-06-11 05:34:45
depth2
children0
net_rshares0
last_payout2018-06-18 05:34:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length107
author_reputation17,874,019,286,870
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@zorank ·
This looks like reverse pre-order tree traversal. Maybe this post on Github could be of some help: https://gist.github.com/sabman/ac577c2f018290e169fa54ae1b0aafe5
properties (22)
post_id52,298,472
authorzorank
permlinkre-gokulnk-nestify-a-flat-json-object-20180609t053644983z
categoryjavascript
json_metadata{}
created2018-06-09 05:36:45
last_update2018-06-09 05:36:45
depth1
children0
net_rshares0
last_payout2018-06-16 05:36:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length162
author_reputation9,898,184,747,299
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries
0.
accountsteem-bounty
weight1,500
max_accepted_payout100,000.000 SBD
percent_steem_dollars10,000
@fresteem ·
$0.02
<center>**Free Resteem For Steem-Bounty Users**</center>
* **Your Post Got Upvote**
* **Your Post Resteemed To 800+ Followers**
**How it Work You can [Check Here](https://steemit.com/steem-bounty/@laconic/fresteem-supports-steem-bounty-project-which-is-developed-by-the-knircky-and-famunger)**

<center>

![Untitled-2.png](https://steemitimages.com/DQmNfTnyknzAnh9nq4aPp2nMsAQAs9wjeHpqGuNK49hApxT/Untitled-2.png)</center>
properties (22)
post_id52,308,303
authorfresteem
permlinkre-gokulnk-nestify-a-flat-json-object-20180609t075008029z
categoryjavascript
json_metadata"{"links": ["https://steemit.com/steem-bounty/@laconic/fresteem-supports-steem-bounty-project-which-is-developed-by-the-knircky-and-famunger"], "image": ["https://steemitimages.com/DQmNfTnyknzAnh9nq4aPp2nMsAQAs9wjeHpqGuNK49hApxT/Untitled-2.png"], "tags": ["javascript"], "app": "steemit/0.1"}"
created2018-06-09 07:50:09
last_update2018-06-09 07:50:09
depth1
children1
net_rshares0
last_payout2018-06-16 07:50:09
cashout_time1969-12-31 23:59:59
total_payout_value0.022 SBD
curator_payout_value0.001 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length421
author_reputation261,684,366,442
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@gokulnk ·
Thanks for the resteem.
properties (22)
post_id52,565,157
authorgokulnk
permlinkre-fresteem-re-gokulnk-nestify-a-flat-json-object-20180611t055430286z
categoryjavascript
json_metadata"{"tags": ["javascript"], "app": "steemit/0.1"}"
created2018-06-11 05:54:18
last_update2018-06-11 05:54:18
depth2
children0
net_rshares0
last_payout2018-06-18 05:54:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length23
author_reputation17,874,019,286,870
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@sparkofphoenix ·
$0.05
Love the dummy names =)
properties (22)
post_id52,311,777
authorsparkofphoenix
permlinkre-gokulnk-nestify-a-flat-json-object-20180609t083229686z
categoryjavascript
json_metadata"{"tags": ["javascript"], "app": "steemit/0.1"}"
created2018-06-09 08:32:30
last_update2018-06-09 08:32:30
depth1
children1
net_rshares0
last_payout2018-06-16 08:32:30
cashout_time1969-12-31 23:59:59
total_payout_value0.038 SBD
curator_payout_value0.008 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length23
author_reputation10,880,946,292,622
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@gokulnk ·
I used the names from one of the examples on a github and just added on to that :)
properties (22)
post_id52,565,119
authorgokulnk
permlinkre-sparkofphoenix-re-gokulnk-nestify-a-flat-json-object-20180611t055402612z
categoryjavascript
json_metadata"{"tags": ["javascript"], "app": "steemit/0.1"}"
created2018-06-11 05:53:51
last_update2018-06-11 05:53:51
depth2
children0
net_rshares0
last_payout2018-06-18 05:53:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length82
author_reputation17,874,019,286,870
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@mightypanda · (edited)
$6.37
Hi @gokulnk,

 I ripped up a quick code with a nested function which takes care of any depth. I have tested my code against your inputs and outputs and it seems to be working fine. Check it out and leave me a comment in git if you find any issue.
https://github.com/mightypanda-x/flat-to-nested
properties (22)
post_id52,317,299
authormightypanda
permlinkre-gokulnk-nestify-a-flat-json-object-20180609t093722712z
categoryjavascript
json_metadata"{"app": "busy/2.4.0", "tags": ["javascript"], "community": "busy"}"
created2018-06-09 09:37:21
last_update2018-06-09 09:37:48
depth1
children3
net_rshares0
last_payout2018-06-16 09:37:21
cashout_time1969-12-31 23:59:59
total_payout_value4.823 SBD
curator_payout_value1.549 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length294
author_reputation21,654,868,736,904
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@gokulnk ·
I had not upvoted your comment because I was testing your code. [I ran some fixed value tests and some random tests.](https://github.com/nkgokul/flat-to-nested/blob/master/nestify.js) Looks like your code is taking care of all the scenarios :) 

Upvoted your answer with 100%. Unless I get a better solution, looks like you are going to be the winner of this Gig.
properties (22)
post_id52,589,685
authorgokulnk
permlinkre-mightypanda-re-gokulnk-nestify-a-flat-json-object-20180611t101906077z
categoryjavascript
json_metadata"{"tags": ["javascript"], "links": ["https://github.com/nkgokul/flat-to-nested/blob/master/nestify.js"], "app": "steemit/0.1"}"
created2018-06-11 10:19:06
last_update2018-06-11 10:19:06
depth2
children1
net_rshares0
last_payout2018-06-18 10:19:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length363
author_reputation17,874,019,286,870
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@mightypanda ·
Glad it worked. I had fun solving it.
properties (22)
post_id52,620,372
authormightypanda
permlinkre-gokulnk-re-mightypanda-re-gokulnk-nestify-a-flat-json-object-20180611t145359749z
categoryjavascript
json_metadata"{"app": "busy/2.4.0", "tags": ["javascript"], "community": "busy"}"
created2018-06-11 14:54:06
last_update2018-06-11 14:54:06
depth3
children0
net_rshares0
last_payout2018-06-18 14:54:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length37
author_reputation21,654,868,736,904
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@hatoto ·
good job!
properties (22)
post_id52,837,070
authorhatoto
permlinkre-mightypanda-re-gokulnk-nestify-a-flat-json-object-20180613t074615587z
categoryjavascript
json_metadata"{"app": "busy/2.4.0", "community": "busy", "tags": ["javascript"]}"
created2018-06-13 07:46:15
last_update2018-06-13 07:46:15
depth2
children0
net_rshares0
last_payout2018-06-20 07:46:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length9
author_reputation12,022,644,346,174
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@lanzjoseg ·
Amigo creo que le falta hacer un cierre en el const output2 falta un ]
properties (22)
post_id52,409,342
authorlanzjoseg
permlinkre-gokulnk-nestify-a-flat-json-object-20180610t014646787z
categoryjavascript
json_metadata"{"tags": ["javascript"], "app": "steemit/0.1"}"
created2018-06-10 01:13:21
last_update2018-06-10 01:13:21
depth1
children0
net_rshares0
last_payout2018-06-17 01:13:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length70
author_reputation305,101,571,399,333
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@adalhelm ·
Wow I don't understand anything in this post ^^ 

I upvote it. Because I'n sure @gokulnk knows what he do ^^
properties (22)
post_id52,457,697
authoradalhelm
permlinkre-gokulnk-nestify-a-flat-json-object-20180610t111307153z
categoryjavascript
json_metadata"{"users": ["gokulnk"], "app": "steemit/0.1", "tags": ["javascript"]}"
created2018-06-10 11:13:09
last_update2018-06-10 11:13:09
depth1
children0
net_rshares0
last_payout2018-06-17 11:13:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length108
author_reputation2,404,978,017,585
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@birapada ·
As a newbie in the programming world,i think this is something i can learn greatly from,i cannot provide an answer but i will surely learn from answers provided by experienced programmers
properties (22)
post_id52,534,817
authorbirapada
permlinkre-gokulnk-nestify-a-flat-json-object-20180610t235758147z
categoryjavascript
json_metadata"{"tags": ["javascript"], "app": "steemit/0.1"}"
created2018-06-10 23:58:03
last_update2018-06-10 23:58:03
depth1
children2
net_rshares0
last_payout2018-06-17 23:58:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length187
author_reputation319,480,565,467
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@gokulnk ·
You have got 25 votes for the comment. You must be really popular in the community. I will be checkout each of the answers and will post my reviews. Lets hope we can both learn things :)
properties (22)
post_id52,563,270
authorgokulnk
permlinkre-birapada-re-gokulnk-nestify-a-flat-json-object-20180611t053322221z
categoryjavascript
json_metadata"{"app": "steemit/0.1", "tags": ["javascript"]}"
created2018-06-11 05:33:09
last_update2018-06-11 05:33:09
depth2
children1
net_rshares0
last_payout2018-06-18 05:33:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length186
author_reputation17,874,019,286,870
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@mightypanda · (edited)
All his comments have exactly 25 up-votes. He is just abusing the bounty system to get larger share. 
https://steemit.com/@birapada/comments.

CC:  @steem-bounty, @knircky
properties (22)
post_id52,568,877
authormightypanda
permlinkre-gokulnk-re-birapada-re-gokulnk-nestify-a-flat-json-object-20180611t063505355z
categoryjavascript
json_metadata"{"links": ["https://steemit.com/@birapada/comments"], "app": "steemit/0.1", "users": ["steem-bounty", "knircky"], "tags": ["javascript"]}"
created2018-06-11 06:34:54
last_update2018-06-11 16:17:30
depth3
children0
net_rshares0
last_payout2018-06-18 06:34:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length171
author_reputation21,654,868,736,904
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@soumon ·
Hi @gokulnk,
No need to explain your code. It is really easy to understand because of your indentations make the code well organized.
properties (22)
post_id52,688,245
authorsoumon
permlinkre-gokulnk-nestify-a-flat-json-object-20180612t024400418z
categoryjavascript
json_metadata"{"users": ["gokulnk"], "tags": ["javascript"], "app": "steemit/0.1"}"
created2018-06-12 02:44:06
last_update2018-06-12 02:44:06
depth1
children0
net_rshares0
last_payout2018-06-19 02:44:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length133
author_reputation747,021,898,927
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@hatoto ·
What a nice use of Steem Bounty! Paying the solver of your problems with Steem Bounty. That's brillant! I will do the same if i have a problem in the future.
properties (22)
post_id52,837,046
authorhatoto
permlinkre-gokulnk-nestify-a-flat-json-object-20180613t074553721z
categoryjavascript
json_metadata"{"app": "busy/2.4.0", "community": "busy", "tags": ["javascript"]}"
created2018-06-13 07:45:51
last_update2018-06-13 07:45:51
depth1
children0
net_rshares0
last_payout2018-06-20 07:45:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length157
author_reputation12,022,644,346,174
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@mdrost ·
Hi @gokulnk
My approach uses recursion https://gist.github.com/mdrost/42b66eb40aede652d0e620b898960e1f
properties (22)
post_id53,026,382
authormdrost
permlinkre-gokulnk-nestify-a-flat-json-object-20180614t193504482z
categoryjavascript
json_metadata"{"tags": ["javascript"], "links": ["https://gist.github.com/mdrost/42b66eb40aede652d0e620b898960e1f"], "users": ["gokulnk"], "app": "steemit/0.1"}"
created2018-06-14 19:35:06
last_update2018-06-14 19:35:06
depth1
children0
net_rshares0
last_payout2018-06-21 19:35:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length102
author_reputation0
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@sfcq240788 ·
Hey man!!! Greetings!!
properties (22)
post_id53,069,678
authorsfcq240788
permlinkre-gokulnk-nestify-a-flat-json-object-20180615t050633628z
categoryjavascript
json_metadata{}
created2018-06-15 05:06:33
last_update2018-06-15 05:06:33
depth1
children0
net_rshares0
last_payout2018-06-22 05:06:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length22
author_reputation3,106,148,552,980
root_title"Steem Bounty : Nestify a flat JSON object"
beneficiaries
0.
accountsteem-bounty
weight1,500
max_accepted_payout100,000.000 SBD
percent_steem_dollars10,000