Update nested state without mutation. Input: line 1 — state JSON; line 2 — a dot path like user.address.city; line 3 — new value (JSON). Print the NEW state JSON; every object on the path must be a new reference (deep-set immutably).
Input: three lines. Output: updated state JSON.
Your program reads from stdin and prints to stdout.
Example 1
Input: {"user":{"address":{"city":"NYC","zip":"1"},"age":30}} user.address.city "LA"
Output: {"user":{"address":{"city":"LA","zip":"1"},"age":30}}
Hints
Update nested state without mutation. Input: line 1 — state JSON; line 2 — a dot path like user.address.city; line 3 — new value (JSON). Print the NEW state JSON; every object on the path must be a new reference (deep-set immutably).
Input: three lines. Output: updated state JSON.
Your program reads from stdin and prints to stdout.
Example 1
Input: {"user":{"address":{"city":"NYC","zip":"1"},"age":30}} user.address.city "LA"
Output: {"user":{"address":{"city":"LA","zip":"1"},"age":30}}
Hints