Perl,使用CPAN的JSON模块:
perl -MJSON -0777 -lne ‘
my $data = decodejson $;
for my $key (keys %$data) {
$data->{$key} = $ENV{$key} if exists $ENV{$key};
}
print encode_json($data);
‘ file.json
</code>
或Ruby,没有外部依赖
ruby -rjson -e ‘
data = JSON.parse(File.read(ARGV.shift))
data.each_key {|key| data[key] = ENV[key] if ENV.has_key? key}
puts JSON.generate(data)
‘ file.json
</code>