输入JSON数据,每个key的首字母可能是大写也可能是小写,此外,输入的JSON可能不包含对象,没有key
输出为JSON,每个key的首字母是大写(如果包含对象)


输入{ “myKey”: “myValue”}
输出{“MyKey”: “myValue”}

Hint
JSON支持多种数据类型,字符串、数字、数组、对象以及null

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function toUpperCase(data) {
if (Array.isArray(data)) {
return data.map(item => toUpperCase(item));
} else if (typeof data === 'object' && data !== null) {
const temp = {};
for (let i in data) {
const newKey = i.substring(0, 1).toUpperCase() + i.substring(1);
temp[newKey] = toUpperCase(data[i]);
}
return temp;
} else {
return data;
}
}
var res;
var _data = read_line();
res = toUpperCase(JSON.parse(_data));
print(JSON.stringify(res));