Make key types based on id

This commit separates out the libcper json output by section name.
Previously, each section was

i.e., for e.g., add "Nvidia" for the NVIDIA section
```
  "sections": [
    {
      "Nvidia":{
          "socket": 0
      }
    }
  ]
```
instead of
```
  "sections": [
    {
        "socket": 0
    }
  ]
```

This allows disambiguating between multiple fields with different types
and removes collisions between the field names.

Change-Id: I4e257f1e04fc5fbf2798955d3a5d93214c81f0fc
Signed-off-by: Karthik Rajagopalan <krajagopalan@nvidia.com>
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/cper-parse.c b/cper-parse.c
index 8c8722d..afedc9d 100644
--- a/cper-parse.c
+++ b/cper-parse.c
@@ -342,12 +342,20 @@
 
 	//Parse section to IR based on GUID.
 	json_object *result = NULL;
+
+	json_object *section_ir = NULL;
 	int section_converted = 0;
 	for (size_t i = 0; i < section_definitions_len; i++) {
 		if (guid_equal(section_definitions[i].Guid,
 			       &descriptor->SectionType) &&
 		    section_definitions[i].ToIR != NULL) {
-			result = section_definitions[i].ToIR(section);
+			section_ir = section_definitions[i].ToIR(section);
+
+			result = json_object_new_object();
+			json_object_object_add(result,
+					       section_definitions[i].ShortName,
+					       section_ir);
+
 			section_converted = 1;
 			break;
 		}
@@ -356,20 +364,23 @@
 	//Was it an unknown GUID/failed read?
 	if (!section_converted) {
 		//Output the data as formatted base64.
-		result = json_object_new_object();
-
 		int32_t encoded_len = 0;
 		char *encoded = base64_encode(
 			section, descriptor->SectionLength, &encoded_len);
 		if (encoded == NULL) {
 			printf("Failed to allocate encode output buffer. \n");
 		} else {
-			json_object_object_add(result, "data",
+			section_ir = json_object_new_object();
+			json_object_object_add(section_ir, "data",
 					       json_object_new_string_len(
 						       encoded, encoded_len));
 			free(encoded);
+
+			result = json_object_new_object();
+			json_object_object_add(result, "Unknown", section_ir);
 		}
 	}
+
 	//Free section memory, return result.
 	free(section);
 	return result;