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
post_id | 52,196,855 | ||||||
---|---|---|---|---|---|---|---|
author | gokulnk | ||||||
permlink | nestify-a-flat-json-object | ||||||
category | javascript | ||||||
json_metadata | "{"format": "markdown", "image": ["https://cdn.steemitimages.com/DQmdfyrfkJwrrHW79XHYRUyjwNumaikhgKH83hzGaJsSh19/javascript.jpg"], "app": "steemit/0.1", "tags": ["javascript", "development", "algorithm", "dev"]}" | ||||||
created | 2018-06-08 11:08:18 | ||||||
last_update | 2018-06-13 08:41:12 | ||||||
depth | 0 | ||||||
children | 31 | ||||||
net_rshares | 2,327,402,837,806 | ||||||
last_payout | 2018-06-15 11:08:18 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 4.070 SBD | ||||||
curator_payout_value | 1.531 SBD | ||||||
pending_payout_value | 0.000 SBD | ||||||
promoted | 0.000 SBD | ||||||
body_length | 2,380 | ||||||
author_reputation | 17,874,019,286,870 | ||||||
root_title | "Steem Bounty : Nestify a flat JSON object" | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 100,000.000 SBD | ||||||
percent_steem_dollars | 10,000 | ||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
knircky | 0 | 2,172,241,536,558 | 100% | ||
ubg | 0 | 1,211,723,024 | 1% | ||
steem-bounty | 0 | 25,385,097,464 | 100% | ||
gokulnk | 0 | 19,893,826,592 | 100% | ||
sbd.jackpot | 0 | 103,685,140 | 2% | ||
fresteem | 0 | 612,095,256 | 100% | ||
fher | 0 | 441,977,476 | 100% | ||
adalhelm | 0 | 2,026,165,076 | 100% | ||
kimtaehyun | 0 | 591,373,821 | 100% | ||
steemladder | 0 | 80,692,412,664 | 100% | ||
hackerzizon | 0 | 204,738,688 | 1% | ||
m2nnari | 0 | 464,473,054 | 100% | ||
elleok | 0 | 6,618,850,791 | 100% | ||
hatoto | 0 | 185,871,054 | 10% | ||
crypticat | 0 | 5,228,846,678 | 30% | ||
mdrost | 0 | 606,612,264 | 100% | ||
dick.sledge | 0 | 6,279,537,463 | 0.85% | ||
aleks02 | 0 | 582,494,063 | 100% | ||
stepanslobodyan | 0 | 582,494,063 | 100% | ||
karinegevorgyan | 0 | 582,494,063 | 100% | ||
johnfogel | 0 | 594,689,090 | 100% | ||
gartiv88 | 0 | 594,689,090 | 100% | ||
blindjab | 0 | 594,689,090 | 100% | ||
ershov21 | 0 | 594,689,090 | 100% | ||
thekausar | 0 | 487,776,194 | 100% |
@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>
post_id | 52,197,020 |
---|---|
author | steem-bounty |
permlink | re-nestify-a-flat-json-object-20180608t111018 |
category | javascript |
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"}" |
created | 2018-06-08 11:10:18 |
last_update | 2018-06-08 11:10:18 |
depth | 1 |
children | 1 |
net_rshares | 0 |
last_payout | 2018-06-15 11:10:18 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 1,539 |
author_reputation | 168,095,294,179,951 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
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!
post_id | 53,097,838 |
---|---|
author | steem-bounty |
permlink | re-re-nestify-a-flat-json-object-20180608t111018-20180615t110903 |
category | javascript |
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"}" |
created | 2018-06-15 11:09:03 |
last_update | 2018-06-15 11:09:03 |
depth | 2 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-06-22 11:09:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 1,668 |
author_reputation | 168,095,294,179,951 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
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!
post_id | 52,219,689 |
---|---|
author | elleok |
permlink | re-gokulnk-nestify-a-flat-json-object-20180608t144735755z |
category | javascript |
json_metadata | "{"tags": ["javascript"], "app": "steemit/0.1"}" |
created | 2018-06-08 14:47:36 |
last_update | 2018-06-08 14:48:18 |
depth | 1 |
children | 1 |
net_rshares | 12,971,536,606 |
last_payout | 2018-06-15 14:47:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.028 SBD |
curator_payout_value | 0.005 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 294 |
author_reputation | 18,431,282,494,259 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
gokulnk | 0 | 410,181,991 | 1% | ||
yougotresteemed | 0 | 1,236,690,421 | 100% | ||
dustsweeper | 0 | 10,714,172,477 | 2.79% | ||
merlinmagic | 0 | 610,491,717 | 100% |
Thanks for the resteem.
post_id | 52,563,570 |
---|---|
author | gokulnk |
permlink | re-elleok-re-gokulnk-nestify-a-flat-json-object-20180611t053617064z |
category | javascript |
json_metadata | "{"app": "steemit/0.1", "tags": ["javascript"]}" |
created | 2018-06-11 05:36:09 |
last_update | 2018-06-11 05:36:09 |
depth | 2 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-06-18 05:36:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 23 |
author_reputation | 17,874,019,286,870 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
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.
post_id | 52,231,290 | ||||||
---|---|---|---|---|---|---|---|
author | jmhb85 | ||||||
permlink | re-gokulnk-nestify-a-flat-json-object-20180608t162839495z | ||||||
category | javascript | ||||||
json_metadata | {} | ||||||
created | 2018-06-08 16:28:39 | ||||||
last_update | 2018-06-08 16:28:39 | ||||||
depth | 1 | ||||||
children | 0 | ||||||
net_rshares | 0 | ||||||
last_payout | 2018-06-15 16:28:39 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 0.000 SBD | ||||||
curator_payout_value | 0.000 SBD | ||||||
pending_payout_value | 0.000 SBD | ||||||
promoted | 0.000 SBD | ||||||
body_length | 578 | ||||||
author_reputation | 6,726,323,919,212 | ||||||
root_title | "Steem Bounty : Nestify a flat JSON object" | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 100,000.000 SBD | ||||||
percent_steem_dollars | 10,000 |
Ok, this is too much for my brain
post_id | 52,236,305 |
---|---|
author | tsnaks |
permlink | re-gokulnk-nestify-a-flat-json-object-20180608t171607480z |
category | javascript |
json_metadata | "{"tags": ["javascript"], "app": "steemit/0.1"}" |
created | 2018-06-08 17:16:06 |
last_update | 2018-06-08 17:16:06 |
depth | 1 |
children | 1 |
net_rshares | 0 |
last_payout | 2018-06-15 17:16:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 33 |
author_reputation | 21,107,871,637,009 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
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.
post_id | 52,564,171 |
---|---|
author | gokulnk |
permlink | re-tsnaks-re-gokulnk-nestify-a-flat-json-object-20180611t054249872z |
category | javascript |
json_metadata | "{"app": "steemit/0.1", "tags": ["javascript"]}" |
created | 2018-06-11 05:42:48 |
last_update | 2018-06-11 05:42:48 |
depth | 2 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-06-18 05:42:48 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 245 |
author_reputation | 17,874,019,286,870 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
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.)
post_id | 52,255,843 |
---|---|
author | malloryblythe |
permlink | re-gokulnk-nestify-a-flat-json-object-20180608t203505353z |
category | javascript |
json_metadata | "{"tags": ["javascript"], "app": "steemit/0.1"}" |
created | 2018-06-08 20:35:06 |
last_update | 2018-06-08 20:35:06 |
depth | 1 |
children | 1 |
net_rshares | 0 |
last_payout | 2018-06-15 20:35:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.023 SBD |
curator_payout_value | 0.005 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 180 |
author_reputation | 2,267,543,125,870 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
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 :)
post_id | 52,565,262 |
---|---|
author | gokulnk |
permlink | re-malloryblythe-re-gokulnk-nestify-a-flat-json-object-20180611t055540251z |
category | javascript |
json_metadata | "{"tags": ["javascript"], "app": "steemit/0.1"}" |
created | 2018-06-11 05:55:30 |
last_update | 2018-06-11 05:55:30 |
depth | 2 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-06-18 05:55:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 142 |
author_reputation | 17,874,019,286,870 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
Deivid vรตi Daweed?
post_id | 52,268,823 |
---|---|
author | m2nnari |
permlink | re-gokulnk-nestify-a-flat-json-object-20180608t230232273z |
category | javascript |
json_metadata | "{"tags": ["javascript"], "app": "steemit/0.1"}" |
created | 2018-06-08 23:02:30 |
last_update | 2018-06-08 23:02:30 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-06-15 23:02:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 18 |
author_reputation | 1,929,992,207,692 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
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
post_id | 52,283,163 |
---|---|
author | crypticat |
permlink | re-gokulnk-nestify-a-flat-json-object-20180609t021244355z |
category | javascript |
json_metadata | "{"links": ["https://github.com/joaonuno/flat-to-nested-js/blob/master/README.md"], "tags": ["javascript"], "app": "steemit/0.1"}" |
created | 2018-06-09 02:12:45 |
last_update | 2018-06-09 02:14:45 |
depth | 1 |
children | 1 |
net_rshares | 0 |
last_payout | 2018-06-16 02:12:45 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.020 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 188 |
author_reputation | 121,774,275,823,341 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
This doesn't solve the problem in question directly. But it does solve one half of it. Thanks for the link.
post_id | 52,563,409 |
---|---|
author | gokulnk |
permlink | re-crypticat-re-gokulnk-nestify-a-flat-json-object-20180611t053450438z |
category | javascript |
json_metadata | "{"app": "steemit/0.1", "tags": ["javascript"]}" |
created | 2018-06-11 05:34:45 |
last_update | 2018-06-11 05:34:45 |
depth | 2 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-06-18 05:34:45 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 107 |
author_reputation | 17,874,019,286,870 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
This looks like reverse pre-order tree traversal. Maybe this post on Github could be of some help: https://gist.github.com/sabman/ac577c2f018290e169fa54ae1b0aafe5
post_id | 52,298,472 | ||||||
---|---|---|---|---|---|---|---|
author | zorank | ||||||
permlink | re-gokulnk-nestify-a-flat-json-object-20180609t053644983z | ||||||
category | javascript | ||||||
json_metadata | {} | ||||||
created | 2018-06-09 05:36:45 | ||||||
last_update | 2018-06-09 05:36:45 | ||||||
depth | 1 | ||||||
children | 0 | ||||||
net_rshares | 0 | ||||||
last_payout | 2018-06-16 05:36:45 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 0.000 SBD | ||||||
curator_payout_value | 0.000 SBD | ||||||
pending_payout_value | 0.000 SBD | ||||||
promoted | 0.000 SBD | ||||||
body_length | 162 | ||||||
author_reputation | 9,898,184,747,299 | ||||||
root_title | "Steem Bounty : Nestify a flat JSON object" | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 100,000.000 SBD | ||||||
percent_steem_dollars | 10,000 |
<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>
post_id | 52,308,303 |
---|---|
author | fresteem |
permlink | re-gokulnk-nestify-a-flat-json-object-20180609t075008029z |
category | javascript |
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"}" |
created | 2018-06-09 07:50:09 |
last_update | 2018-06-09 07:50:09 |
depth | 1 |
children | 1 |
net_rshares | 0 |
last_payout | 2018-06-16 07:50:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.022 SBD |
curator_payout_value | 0.001 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 421 |
author_reputation | 261,684,366,442 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
Thanks for the resteem.
post_id | 52,565,157 |
---|---|
author | gokulnk |
permlink | re-fresteem-re-gokulnk-nestify-a-flat-json-object-20180611t055430286z |
category | javascript |
json_metadata | "{"tags": ["javascript"], "app": "steemit/0.1"}" |
created | 2018-06-11 05:54:18 |
last_update | 2018-06-11 05:54:18 |
depth | 2 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-06-18 05:54:18 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 23 |
author_reputation | 17,874,019,286,870 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
Love the dummy names =)
post_id | 52,311,777 |
---|---|
author | sparkofphoenix |
permlink | re-gokulnk-nestify-a-flat-json-object-20180609t083229686z |
category | javascript |
json_metadata | "{"tags": ["javascript"], "app": "steemit/0.1"}" |
created | 2018-06-09 08:32:30 |
last_update | 2018-06-09 08:32:30 |
depth | 1 |
children | 1 |
net_rshares | 0 |
last_payout | 2018-06-16 08:32:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.038 SBD |
curator_payout_value | 0.008 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 23 |
author_reputation | 10,880,946,292,622 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
I used the names from one of the examples on a github and just added on to that :)
post_id | 52,565,119 |
---|---|
author | gokulnk |
permlink | re-sparkofphoenix-re-gokulnk-nestify-a-flat-json-object-20180611t055402612z |
category | javascript |
json_metadata | "{"tags": ["javascript"], "app": "steemit/0.1"}" |
created | 2018-06-11 05:53:51 |
last_update | 2018-06-11 05:53:51 |
depth | 2 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-06-18 05:53:51 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 82 |
author_reputation | 17,874,019,286,870 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
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
post_id | 52,317,299 |
---|---|
author | mightypanda |
permlink | re-gokulnk-nestify-a-flat-json-object-20180609t093722712z |
category | javascript |
json_metadata | "{"app": "busy/2.4.0", "tags": ["javascript"], "community": "busy"}" |
created | 2018-06-09 09:37:21 |
last_update | 2018-06-09 09:37:48 |
depth | 1 |
children | 3 |
net_rshares | 0 |
last_payout | 2018-06-16 09:37:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 4.823 SBD |
curator_payout_value | 1.549 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 294 |
author_reputation | 21,654,868,736,904 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
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.
post_id | 52,589,685 |
---|---|
author | gokulnk |
permlink | re-mightypanda-re-gokulnk-nestify-a-flat-json-object-20180611t101906077z |
category | javascript |
json_metadata | "{"tags": ["javascript"], "links": ["https://github.com/nkgokul/flat-to-nested/blob/master/nestify.js"], "app": "steemit/0.1"}" |
created | 2018-06-11 10:19:06 |
last_update | 2018-06-11 10:19:06 |
depth | 2 |
children | 1 |
net_rshares | 0 |
last_payout | 2018-06-18 10:19:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 363 |
author_reputation | 17,874,019,286,870 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
Glad it worked. I had fun solving it.
post_id | 52,620,372 |
---|---|
author | mightypanda |
permlink | re-gokulnk-re-mightypanda-re-gokulnk-nestify-a-flat-json-object-20180611t145359749z |
category | javascript |
json_metadata | "{"app": "busy/2.4.0", "tags": ["javascript"], "community": "busy"}" |
created | 2018-06-11 14:54:06 |
last_update | 2018-06-11 14:54:06 |
depth | 3 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-06-18 14:54:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 37 |
author_reputation | 21,654,868,736,904 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
good job!
post_id | 52,837,070 |
---|---|
author | hatoto |
permlink | re-mightypanda-re-gokulnk-nestify-a-flat-json-object-20180613t074615587z |
category | javascript |
json_metadata | "{"app": "busy/2.4.0", "community": "busy", "tags": ["javascript"]}" |
created | 2018-06-13 07:46:15 |
last_update | 2018-06-13 07:46:15 |
depth | 2 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-06-20 07:46:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 9 |
author_reputation | 12,022,644,346,174 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
Amigo creo que le falta hacer un cierre en el const output2 falta un ]
post_id | 52,409,342 |
---|---|
author | lanzjoseg |
permlink | re-gokulnk-nestify-a-flat-json-object-20180610t014646787z |
category | javascript |
json_metadata | "{"tags": ["javascript"], "app": "steemit/0.1"}" |
created | 2018-06-10 01:13:21 |
last_update | 2018-06-10 01:13:21 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-06-17 01:13:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 70 |
author_reputation | 305,101,571,399,333 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
Wow I don't understand anything in this post ^^ I upvote it. Because I'n sure @gokulnk knows what he do ^^
post_id | 52,457,697 |
---|---|
author | adalhelm |
permlink | re-gokulnk-nestify-a-flat-json-object-20180610t111307153z |
category | javascript |
json_metadata | "{"users": ["gokulnk"], "app": "steemit/0.1", "tags": ["javascript"]}" |
created | 2018-06-10 11:13:09 |
last_update | 2018-06-10 11:13:09 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-06-17 11:13:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 108 |
author_reputation | 2,404,978,017,585 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
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
post_id | 52,534,817 |
---|---|
author | birapada |
permlink | re-gokulnk-nestify-a-flat-json-object-20180610t235758147z |
category | javascript |
json_metadata | "{"tags": ["javascript"], "app": "steemit/0.1"}" |
created | 2018-06-10 23:58:03 |
last_update | 2018-06-10 23:58:03 |
depth | 1 |
children | 2 |
net_rshares | 0 |
last_payout | 2018-06-17 23:58:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 187 |
author_reputation | 319,480,565,467 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
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 :)
post_id | 52,563,270 |
---|---|
author | gokulnk |
permlink | re-birapada-re-gokulnk-nestify-a-flat-json-object-20180611t053322221z |
category | javascript |
json_metadata | "{"app": "steemit/0.1", "tags": ["javascript"]}" |
created | 2018-06-11 05:33:09 |
last_update | 2018-06-11 05:33:09 |
depth | 2 |
children | 1 |
net_rshares | 0 |
last_payout | 2018-06-18 05:33:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 186 |
author_reputation | 17,874,019,286,870 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
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
post_id | 52,568,877 |
---|---|
author | mightypanda |
permlink | re-gokulnk-re-birapada-re-gokulnk-nestify-a-flat-json-object-20180611t063505355z |
category | javascript |
json_metadata | "{"links": ["https://steemit.com/@birapada/comments"], "app": "steemit/0.1", "users": ["steem-bounty", "knircky"], "tags": ["javascript"]}" |
created | 2018-06-11 06:34:54 |
last_update | 2018-06-11 16:17:30 |
depth | 3 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-06-18 06:34:54 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 171 |
author_reputation | 21,654,868,736,904 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
Hi @gokulnk, No need to explain your code. It is really easy to understand because of your indentations make the code well organized.
post_id | 52,688,245 |
---|---|
author | soumon |
permlink | re-gokulnk-nestify-a-flat-json-object-20180612t024400418z |
category | javascript |
json_metadata | "{"users": ["gokulnk"], "tags": ["javascript"], "app": "steemit/0.1"}" |
created | 2018-06-12 02:44:06 |
last_update | 2018-06-12 02:44:06 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-06-19 02:44:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 133 |
author_reputation | 747,021,898,927 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
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.
post_id | 52,837,046 |
---|---|
author | hatoto |
permlink | re-gokulnk-nestify-a-flat-json-object-20180613t074553721z |
category | javascript |
json_metadata | "{"app": "busy/2.4.0", "community": "busy", "tags": ["javascript"]}" |
created | 2018-06-13 07:45:51 |
last_update | 2018-06-13 07:45:51 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-06-20 07:45:51 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 157 |
author_reputation | 12,022,644,346,174 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
Hi @gokulnk My approach uses recursion https://gist.github.com/mdrost/42b66eb40aede652d0e620b898960e1f
post_id | 53,026,382 |
---|---|
author | mdrost |
permlink | re-gokulnk-nestify-a-flat-json-object-20180614t193504482z |
category | javascript |
json_metadata | "{"tags": ["javascript"], "links": ["https://gist.github.com/mdrost/42b66eb40aede652d0e620b898960e1f"], "users": ["gokulnk"], "app": "steemit/0.1"}" |
created | 2018-06-14 19:35:06 |
last_update | 2018-06-14 19:35:06 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-06-21 19:35:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 102 |
author_reputation | 0 |
root_title | "Steem Bounty : Nestify a flat JSON object" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
Hey man!!! Greetings!!
post_id | 53,069,678 | ||||||
---|---|---|---|---|---|---|---|
author | sfcq240788 | ||||||
permlink | re-gokulnk-nestify-a-flat-json-object-20180615t050633628z | ||||||
category | javascript | ||||||
json_metadata | {} | ||||||
created | 2018-06-15 05:06:33 | ||||||
last_update | 2018-06-15 05:06:33 | ||||||
depth | 1 | ||||||
children | 0 | ||||||
net_rshares | 0 | ||||||
last_payout | 2018-06-22 05:06:33 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 0.000 SBD | ||||||
curator_payout_value | 0.000 SBD | ||||||
pending_payout_value | 0.000 SBD | ||||||
promoted | 0.000 SBD | ||||||
body_length | 22 | ||||||
author_reputation | 3,106,148,552,980 | ||||||
root_title | "Steem Bounty : Nestify a flat JSON object" | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 100,000.000 SBD | ||||||
percent_steem_dollars | 10,000 |