1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/docs/parsers/free.md
Kelly Brazil 1d0ad2f045 doc fixes
2021-01-04 18:01:16 -08:00

1.8 KiB

jc.parsers.free

jc - JSON CLI output utility free command output parser

Usage (cli):

$ free | jc --free

or

$ jc free

Usage (module):

import jc.parsers.free
result = jc.parsers.free.parse(free_command_output)

Compatibility:

'linux'

Examples:

$ free | jc --free -p
[
  {
    "type": "Mem",
    "total": 3861340,
    "used": 220508,
    "free": 3381972,
    "shared": 11800,
    "buff_cache": 258860,
    "available": 3397784
  },
  {
    "type": "Swap",
    "total": 2097148,
    "used": 0,
    "free": 2097148
  }
]

$ free | jc --free -p -r
[
  {
    "type": "Mem",
    "total": "2017300",
    "used": "213104",
    "free": "1148452",
    "shared": "1176",
    "buff_cache": "655744",
    "available": "1622204"
  },
  {
    "type": "Swap",
    "total": "2097148",
    "used": "0",
    "free": "2097148"
  }
]

info

info()

process

process(proc_data)

Final processing to conform to the schema.

Parameters:

proc_data:   (List of Dictionaries) raw structured data to process

Returns:

List of Dictionaries. Structured data with the following schema:

[
  {
    "type":         string,
    "total":        integer,
    "used":         integer,
    "free":         integer,
    "shared":       integer,
    "buff_cache":   integer,
    "available":    integer
  }
]

parse

parse(data, raw=False, quiet=False)

Main text parsing function

Parameters:

data:        (string)  text data to parse
raw:         (boolean) output preprocessed JSON if True
quiet:       (boolean) suppress warning messages if True

Returns:

List of Dictionaries. Raw or processed structured data.