JSON to Object - JavaScript -


i trying take json list formatted such: (real list has on 2500 entries).

  [      ['fb.com', 'http://facebook.com/']      ['ggle.com', 'http://google.com/']   ] 

the json list represents: ['request url', 'destination url']. redirect audit tool built on node.js.

the goal put json value pairs in javascript object key value array pair such:

    var importedurls = {             requesturl : [                              'fb.com',                              'ggle.com'                          ],         destinationurl : [                              'https://www.facebook.com/',                              'http://www.google.com/'                           ]     } 

due sheer amount of redirects, prefer nonblocking solution if possible.

you first need create object:

var importedurls = {   requesturl: [],   destinationurl: [] } 

now, let's have data in array called importeddata lack of better name. can iterate array , push each value proper new array:

importeddata.foreach(function(urls){   importedurls.requesturl.push(urls[0]);   importedurls.destinationurl.push(urls[1]); }); 

this format object want formatted, hope.

i propose you take approach. why not have array of importedurls, each 1 correspondent keys?

you have like:

importedurls = [   {      requesturl: 'req',      destinationurl: 'dest'   },   {      requesturl: 'req2',      destinationurl: 'dest2'   }, ] 

i'm sure can figure out how tweak code showed fit format if want to. gain clear separation of urls , makes iterations lot more intuitive.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -