find the last modified date of a json file in ruby

You can use the File class and JSON module in Ruby to read the json file and get its last modified date. Here's an example:

main.rb
require 'json'

file_path = 'path/to/file.json'

# get the last modified time of the file
last_modified_time = File.mtime(file_path)

# read the json file
json_data = JSON.parse(File.read(file_path))

# do something with the json data

# print the last modified time
puts "Last modified time: #{last_modified_time}"
316 chars
15 lines

In this example, we first get the last modified time of the json file using File.mtime. We then read the contents of the file using File.read, and parse the json data using JSON.parse. Finally, we print the last modified time using puts.

related categories

gistlibby LogSnag