-1

The text file contains the below array.

[  
   {  
      "title":"Test Report",
      "htmlpath":"C:\\sample.html",
      "browser":"phantomjs",
      "browser_version":"2.1.1",
      "time":"0h 0min 0s5",
      "testresults":"passed: 1 failed: 0 skipped: 2"
   }
]

[  
   {  
      "title":"Test Report",
      "htmlpath":"C:\\sample1.html",
      "browser":"internet explorer",
      "browser_version":"11",
      "time":"0h 0min 0s8",
      "testresults":"passed: 1 failed: 0 skipped: 2"
   }
]

I would like to read the above text file using Javascript, parse it as an associative array. Use this array and create a table for the Key value pair and display in the HTML. Please help with the existing code to achieve this.

Jeremy Thille
  • 26,047
  • 12
  • 43
  • 63
Basil
  • 77
  • 2
  • 9
  • Is this supposed to be two arrays of one object each? – Jeremy Thille May 22 '17 at 12:09
  • http://stackoverflow.com/questions/14446447/javascript-read-local-text-file shows how to read a file – Plankton May 22 '17 at 12:14
  • what ur effort?? what code did u write ?? – Plankton May 22 '17 at 12:14
  • This is not a free coding service; people are generally not going to be willing to just write your program for you. If you show what you've tried already, or give some evidence that you've at least attempted to tackle the problem, you're much likelier to get useful answers. – Daniel Beck May 22 '17 at 12:17

1 Answers1

0

First of all, you need a server in order to read a file. Browsers don't give direct access to the filesystem (that would be a HUGE security issue).

With NodeJS, you can read and parse a JSON in a text file, like this :

readFile("mydata.json", (error, text) => console.log( JSON.parse(text) ) )

Then, iterate over your json data and build a table with whatever framework you want (jQuery, Angular, etc)

Jeremy Thille
  • 26,047
  • 12
  • 43
  • 63