Guest User

Untitled

a guest
Oct 23rd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. jsonArray = JSON.parse(File.open(JSON_filePath).read)
  2. jsonArray << node_to_insert
  3.  
  4. File.open(JSON_FilePath,"w") do |f|
  5. f.write(JSON.pretty_generate(jsonArray))
  6. end
  7.  
  8. jsonArray = [node_to_insert] # initialize to array with your first row
  9. jsonArray.push( *JSON.parse(File.open(JSON_filePath).read) ) # push results,
  10. # use the splat operator (*) to avoid array nesting
  11.  
  12. jsonArray = JSON.parse(File.open(JSON_filePath).read)
  13. jsonArray.prepend(node_to_insert)
Add Comment
Please, Sign In to add comment