This is also a sample problem. Good luck!
Create a program to count the number of primitive elements of a JSON data structure. That is, count the number of strings, numbers, boolean constants, and null. Arrays ([…]) and objects ({…}) are NOT counted, but their descendant elements, if any, are counted.
Each dataset is an ASCII-encoded file containing a single JSON data structure. For example the following is a possible input file.
{
"people": [
{
"name": "Joe Someone",
"age": 56,
"spouse": null,
"height": 1.87,
"weight": 67.5,
"retired": true,
"degrees": [ ]
},
{
"name": "Jan Someone",
"age": 53,
"spouse": "John Doe",
"weight": 757.1,
"retired": false,
"degrees": [
"BS",
"MS",
"PhD"
]
}
]
}
Your program should count the number of primitive elements as described above. For example the above input should produce the following.
{
"answer" : 14
}