Serializes value to JSON using json and writes it to the file under path, creating parent directories if necessary.