[Bug 197499] wc libxo emits invalid JSON when used on multiple files

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Mon Feb 9 20:31:11 UTC 2015


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=197499

            Bug ID: 197499
           Summary: wc libxo emits invalid JSON when used on multiple
                    files
           Product: Base System
           Version: 11.0-CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: bin
          Assignee: freebsd-bugs at FreeBSD.org
          Reporter: allanjude at FreeBSD.org

When using wc's libxo JSON output method, it emits invalid JSON.

Steps to recreate:

wc --libxo json /etc/defaults/*



The output is (pretty-printed for readability):



{
  "wc": {
    "file": [
      {
        "lines": 111,
        "words": 644,
        "characters": 3999,
        "filename": "/etc/defaults/bluetooth.device.conf"
      },
      {
        "lines": 87,
        "words": 403,
        "characters": 2439,
        "filename": "/etc/defaults/devfs.rules"
      },
      {
        "lines": 385,
        "words": 1228,
        "characters": 11700,
        "filename": "/etc/defaults/periodic.conf"
      },
      {
        "lines": 692,
        "words": 4576,
        "characters": 36171,
        "filename": "/etc/defaults/rc.conf"
      },
      "total": {
        "lines": 1275,
        "words": 6851,
        "characters": 54309,
        "filename": "total"
      }
    ]
  }
}


The problem is that the 'total' segment, is a key/value pair, but that is not
allowed inside an array.

The output would either need to be changed to remove the key (the other
elements in the array use the filename for identification), or be made a
sibling of the 'file' 2nd level element, like so:

{
  "wc": {
    "file": [
      {
        "lines": 111,
        "words": 644,
        "characters": 3999,
        "filename": "/etc/defaults/bluetooth.device.conf"
      },
      {
        "lines": 87,
        "words": 403,
        "characters": 2439,
        "filename": "/etc/defaults/devfs.rules"
      },
      {
        "lines": 385,
        "words": 1228,
        "characters": 11700,
        "filename": "/etc/defaults/periodic.conf"
      },
      {
        "lines": 692,
        "words": 4576,
        "characters": 36171,
        "filename": "/etc/defaults/rc.conf"
      }
    ],
    "total": {
      "lines": 1275,
      "words": 6851,
      "characters": 54309,
      "filename": "total"
    }
  }
}

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list