I am looking to rename a variable with a different name depending on its level within a nested JSON dataset.
An example JSON file is the following:
[
  {
    key: "John Doe School",
    values: [
      {
        key: "Mr. Brown",
        values: [
          {
            key: "Joe",
            TestScore: 95
          },
          {
            key: "Sarah",
            TestScore: 99
          }
        ]
      }
    ]
  }
]
In this example, I would like to change the first-level "key" to "School", the second-level "key" to "Teacher", and the third-level "key" to "Student".
The JSON dataset would look like this following the changes:
[
  {
    School: "John Doe School",
    values: [
      {
        Teacher: "Mr. Brown",
        values: [
          {
            Student: "Joe",
            TestScore: 95
          },
          {
            Student: "Sarah",
            TestScore: 99
          }
        ]
      }
    ]
  }
]
 
    