You want something like
use Cpanel::JSON::XS qw( decode_json encode_json ); use File::Slurper qw( read_binary ); my $watchers_data = decode_json( read_binary( $ARGV[0] ) ); my %watchers_lkup = map { $_->{ externalId } => $_->{ watchers } } @$watchers_data; my $data = decode_json( read_binary( $ARGV[1] ) ); $_->{ watchers } = $watchers_lkup{ $_->{ externalId } } for @$data; print encode_json( $data );
Using jq:
jq -n ' ( input | map( { key: .externalId, value: .watchers } ) | from_entries ) as $watchers_lkup | inputs | map( .watchers = $watchers_lkup[ .externalId ] ) ' watchers.json file.json
Demo on jqplay.
In reply to Re: Combine 2 JSON files
by ikegami
in thread Combine 2 JSON files
by gabecz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |