I wrote a small script which loops my current Jsonfile but it's not possible to append a key and value.
This is my file
[
{
"URL": "https://p59-caldav.icloud.com",
}
]
I would like to append a key and value like this
[
{
"URL": "https://p59-caldav.icloud.com",
"test": "test"
}
]
My current script setup
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
require 'domainatrix'
jsonHash = File.read("/Users/ReffasCode/Desktop/sampleData.json")
array = JSON.parse(jsonHash)
File.open("/Users/BilalReffas/Desktop/sampleData.json","w") do |f|
array.each do |child|
url = Domainatrix.parse(child["URL"])
json = {
"url" => child["URL"],
"provider" => url.domain,
"service" => url.subdomain,
"context" => url.path,
"suffix" => url.public_suffix
}
f.write(JSON.pretty_generate(json))
end
end
The script overwrite my whole jsonfile...this is not what I want :/