Merge cached items with a fresh response by id — fresh wins, order: all cached (updated in place), then new fresh items in response order. Input: two lines — cached JSON array and fresh JSON array of {"id", "v"}. Print the merged JSON array.
Input: two JSON arrays. Output: merged JSON array.
Your program reads from stdin and prints to stdout.
Example 1
Input: [{"id":1,"v":"old"},{"id":2,"v":"keep"}] [{"id":1,"v":"new"},{"id":3,"v":"add"}]
Output: [{"id":1,"v":"new"},{"id":2,"v":"keep"},{"id":3,"v":"add"}]
Hints
Merge cached items with a fresh response by id — fresh wins, order: all cached (updated in place), then new fresh items in response order. Input: two lines — cached JSON array and fresh JSON array of {"id", "v"}. Print the merged JSON array.
Input: two JSON arrays. Output: merged JSON array.
Your program reads from stdin and prints to stdout.
Example 1
Input: [{"id":1,"v":"old"},{"id":2,"v":"keep"}] [{"id":1,"v":"new"},{"id":3,"v":"add"}]
Output: [{"id":1,"v":"new"},{"id":2,"v":"keep"},{"id":3,"v":"add"}]
Hints