Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

nodejs append to json

//Because we want JSON format to the file, we first need to read the file
//parse the data to JS object
//push the new items
//and then overwrite the file
var fs = require('fs')

var currentSearchResult = 'example'

fs.readFile('results.json', function (err, data) {
    var json = JSON.parse(data)
    json.push('search result: ' + currentSearchResult)

    fs.writeFile("results.json", JSON.stringify(json))
})
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #nodejs #append #json
ADD COMMENT
Topic
Name
5+4 =