How to build a JSON object using collection of dot notation strings using JavaScript?

ⅰ亾dé卋堺 提交于 2021-02-11 18:19:43

问题


I have a collection of strings in an array. These strings are the JSON paths that i select from a checkbox tree.

var selected = ['a', 'b.c.0.d', 'b.c.1.d', 'b.c.0.e', 'b.c.1.e'];

I want to save it to the database with the real data given by the user. So i want to create a JSON object like following structure. It can be further nested.


    { 
       "a":5,
       "b":{ 
          "c":[ 
             { 
                "d":5,
                "e":5
             },
             { 
                "d":5,
                "e":5
             }
          ]
       }
    }

来源:https://stackoverflow.com/questions/59882169/how-to-build-a-json-object-using-collection-of-dot-notation-strings-using-javasc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!