When serializing with JSON_C_TO_STRING_PRETTY set, keep the opening and closing curly or square braces on same line for empty objects or arrays. Issue #778.

This commit is contained in:
Eric Haszlakiewicz
2022-07-30 19:27:14 +00:00
parent 2e9b7456a5
commit 9749b0cb66
9 changed files with 42 additions and 20 deletions

View File

@@ -311,6 +311,11 @@ int main(int argc, char **argv)
{
printf("\t%s: %s\n", key, json_object_to_json_string(val));
}
json_object *empty_array = json_object_new_array();
json_object *empty_obj = json_object_new_object();
json_object_object_add(my_object, "empty_array", empty_array);
json_object_object_add(my_object, "empty_obj", empty_obj);
printf("my_object.to_string()=%s\n", json_object_to_json_string(my_object));
json_object_put(my_array);

View File

@@ -75,4 +75,4 @@ my_object=
foo: "bar"
bool0: false
bool1: true
my_object.to_string()={ "abc": 12, "foo": "bar", "bool0": false, "bool1": true }
my_object.to_string()={ "abc": 12, "foo": "bar", "bool0": false, "bool1": true, "empty_array": [ ], "empty_obj": { } }

View File

@@ -75,4 +75,4 @@ my_object=
foo: "bar"
bool0: false
bool1: true
my_object.to_string()={"abc":12,"foo":"bar","bool0":false,"bool1":true}
my_object.to_string()={"abc":12,"foo":"bar","bool0":false,"bool1":true,"empty_array":[],"empty_obj":{}}

View File

@@ -97,5 +97,7 @@ my_object.to_string()={
"abc":12,
"foo":"bar",
"bool0":false,
"bool1":true
"bool1":true,
"empty_array":[],
"empty_obj":{}
}

View File

@@ -75,4 +75,4 @@ my_object=
foo: "bar"
bool0: false
bool1: true
my_object.to_string()={ "abc": 12, "foo": "bar", "bool0": false, "bool1": true }
my_object.to_string()={ "abc": 12, "foo": "bar", "bool0": false, "bool1": true, "empty_array": [ ], "empty_obj": { } }

View File

@@ -97,5 +97,7 @@ my_object.to_string()={
"abc": 12,
"foo": "bar",
"bool0": false,
"bool1": true
"bool1": true,
"empty_array": [],
"empty_obj": {}
}

View File

@@ -97,5 +97,7 @@ my_object.to_string()={
"abc": 12,
"foo": "bar",
"bool0": false,
"bool1": true
"bool1": true,
"empty_array": [],
"empty_obj": {}
}