#C14002. Extract Value from JSON
Extract Value from JSON
Extract Value from JSON
You are given a JSON string and a key, provided via standard input. Your task is to extract and print the value associated with the specified key from the JSON string.
If the key exists in the valid JSON, print its corresponding value. If the key does not exist, print Key not found
. If the JSON is invalid (for example, due to a syntax error), print Invalid JSON
.
Note: The value can be of type string or number. When printing a string value, output it without additional quotes.
inputFormat
The input consists of two lines. The first line contains the JSON string. The second line contains the key to be searched.
outputFormat
Output the value associated with the key if it exists. Otherwise, output 'Key not found' if the key is not present, or 'Invalid JSON' if the JSON string is malformed.## sample
{"name": "Alice", "age": 30}
name
Alice