diff mbox series

[5/6] jshn.c: add_json_element():

Message ID 20210223133658.19741-2-stokito@gmail.com
State New
Headers show
Series None | expand

Commit Message

Sergey Ponomarev Feb. 23, 2021, 1:36 p.m. UTC
Extract variable to store json_object_get_type()
Replace switch with json_type_to_name()

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
---
 jshn.c | 32 ++++----------------------------
 1 file changed, 4 insertions(+), 28 deletions(-)
diff mbox series

Patch

diff --git a/jshn.c b/jshn.c
index 43a82e0..6490fbc 100644
--- a/jshn.c
+++ b/jshn.c
@@ -106,38 +106,14 @@  static void write_key_string(const char *key)
 
 static int add_json_element(const char *key, json_object *obj)
 {
-	char *type;
+	enum json_type obj_json_type;
 
-	switch (json_object_get_type(obj)) {
-	case json_type_object:
-		type = "object";
-		break;
-	case json_type_array:
-		type = "array";
-		break;
-	case json_type_string:
-		type = "string";
-		break;
-	case json_type_boolean:
-		type = "boolean";
-		break;
-	case json_type_int:
-		type = "int";
-		break;
-	case json_type_double:
-		type = "double";
-		break;
-	case json_type_null:
-		type = "null";
-		break;
-	default:
-		return -1;
-	}
+	obj_json_type = json_object_get_type(obj);
 
-	fprintf(stdout, "json_add_%s '", type);
+	fprintf(stdout, "json_add_%s '", json_type_to_name(obj_json_type));
 	write_key_string(key);
 
-	switch (json_object_get_type(obj)) {
+	switch (obj_json_type) {
 	case json_type_object:
 		fprintf(stdout, "';\n");
 		add_json_object(obj);