diff --git a/README.md b/README.md index b48d27b7..8a6862c5 100755 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ $ free | jc --free -p "used": "213104", "free": "1148452", "shared": "1176", - "buff/cache": "655744", + "buff_cache": "655744", "available": "1622204" }, { diff --git a/jc/parsers/free.py b/jc/parsers/free.py index fb206746..9f24c5a9 100644 --- a/jc/parsers/free.py +++ b/jc/parsers/free.py @@ -13,7 +13,7 @@ $ free | jc --free -p "used": "213104", "free": "1148452", "shared": "1176", - "buff/cache": "655744", + "buff_cache": "655744", "available": "1622204" }, { @@ -33,9 +33,12 @@ def parse(data): cleandata = data.splitlines() headers = [h for h in ' '.join(cleandata[0].strip().split()).split() if h] - headers.insert(0, "type") + # clean up 'buff/cache' header + # even though forward slash in a key is valid json, it can make things difficult + headers = ['buff_cache' if x == 'buff/cache' else x for x in headers] + raw_data = map(lambda s: s.strip().split(None, len(headers) - 1), cleandata[1:]) output = [dict(zip(headers, r)) for r in raw_data]