1

Output:

{"PSM": {"LinkName": "ath6", "LinkType": "WiFi", "PriorityTag": 1, "Pvid": 106}, "SYSCFG": {"LinkName": "ath6", "LinkType": "WiFi", "PriorityTag": 0, "Pvid": 107}, "rbus_event": {"LinkName": "ath6", "LinkType": "WiFi", "PriorityTag": 0, "Pvid": 108}, "SYSEVENT": {"LinkName": "ath6", "LinkType": "WiFi", "PriorityTag": 0, "Pvid": 109}}

Expected Output:

{"PSM": {
"LinkName": "ath6",
 "LinkType": "WiFi", 
 "PriorityTag": 1, 
 "Pvid": 106}, 
"SYSCFG": {
"LinkName": "ath6", 
 "LinkType": "WiFi",
 "PriorityTag": 0,
 "Pvid": 107},
 "rbus_event": {
"LinkName": "ath6",
 "LinkType": "WiFi",
 "PriorityTag": 0,
 "Pvid": 108},
 "SYSEVENT": {
"LinkName": "ath6",
 "LinkType": "WiFi",
 "PriorityTag": 0,
 "Pvid": 109}}
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
charan
  • 11
  • 1
  • Why do you need a newline for "very[sic] key"? Is the resulting output supposed to be human readable, or only computer readable? If only computer readable, then it doesn't matter. – Some programmer dude Feb 14 '22 at 07:26
  • 1
    And what have you tried? Please take some time to read [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Also please learn how to [edit] your questions to improve them, like showing us a [mre] of your attempt. – Some programmer dude Feb 14 '22 at 07:31

1 Answers1

1

You get a prettified output of your JSON when encoding with a proper indentation.

If you read a JSON which is not already prettified you have to decode it first and encode it the way you want - something like:

json_t *root = json_loads(input, 0, &error);

if (root) {
    char *dump = json_dumps(root, JSON_INDENT(4));
    
    if (dump) {
        printf("%s", dump);
        free(dump);
        dump = NULL;
    }
}
    
Odysseus
  • 1,213
  • 4
  • 12