mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-07 00:57:22 +02:00
coerce non-json-serializable objects to strings
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
jc changelog
|
jc changelog
|
||||||
|
|
||||||
20241119 v1.25.4
|
20241120 v1.25.4
|
||||||
- Add `ipconfig` command parser (`ipconfig` for Windows)
|
- Add `ipconfig` command parser (`ipconfig` for Windows)
|
||||||
- Enhance `ethtool` parser to support `link_partner_advertised_link_modes`
|
- Enhance `ethtool` parser to support `link_partner_advertised_link_modes`
|
||||||
- Enhance `ifconfig` parser to support `utun` interfaces with assigned IPv4 addresses on macOS
|
- Enhance `ifconfig` parser to support `utun` interfaces with assigned IPv4 addresses on macOS
|
||||||
@ -16,6 +16,7 @@ jc changelog
|
|||||||
- Fix `uptime` parser for data that contains `user` instead of `users`
|
- Fix `uptime` parser for data that contains `user` instead of `users`
|
||||||
- Fix `yaml` parser to support values that start with an equal sign
|
- Fix `yaml` parser to support values that start with an equal sign
|
||||||
- Enhance `jc.utils.convert_size_to_int()` to add `posix_mode` and `decimal_bias` parameters
|
- Enhance `jc.utils.convert_size_to_int()` to add `posix_mode` and `decimal_bias` parameters
|
||||||
|
- Enhance cli to coerce any non-JSON-serializable objects to a string
|
||||||
|
|
||||||
20240609 v1.25.3
|
20240609 v1.25.3
|
||||||
- Enhance `bluetoothctl` parser with added `battery_percentage` field
|
- Enhance `bluetoothctl` parser with added `battery_percentage` field
|
||||||
|
@ -401,11 +401,16 @@ class JcCli():
|
|||||||
self.json_indent = 2
|
self.json_indent = 2
|
||||||
self.json_separators = None
|
self.json_separators = None
|
||||||
|
|
||||||
|
# Convert any non-serializable object to a string
|
||||||
|
def string_serializer(data):
|
||||||
|
return str(data)
|
||||||
|
|
||||||
j_string = json.dumps(
|
j_string = json.dumps(
|
||||||
self.data_out,
|
self.data_out,
|
||||||
indent=self.json_indent,
|
indent=self.json_indent,
|
||||||
separators=self.json_separators,
|
separators=self.json_separators,
|
||||||
ensure_ascii=self.ascii_only
|
ensure_ascii=self.ascii_only,
|
||||||
|
default=string_serializer
|
||||||
)
|
)
|
||||||
|
|
||||||
if not self.mono and PYGMENTS_INSTALLED:
|
if not self.mono and PYGMENTS_INSTALLED:
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
import sys
|
import sys
|
||||||
from typing import Any, Dict, List, Tuple, Iterator, Optional, Union
|
from typing import Any, Dict, List, Tuple, Iterator, Optional, Union
|
||||||
|
|
||||||
|
CustomColorType = Dict[Any, str]
|
||||||
JSONDictType = Dict[str, Any]
|
JSONDictType = Dict[str, Any]
|
||||||
StreamingOutputType = Iterator[Union[JSONDictType, Tuple[BaseException, str]]]
|
StreamingOutputType = Iterator[Union[JSONDictType, Tuple[BaseException, str]]]
|
||||||
|
|
||||||
@ -42,11 +43,3 @@ if sys.version_info >= (3, 8):
|
|||||||
else:
|
else:
|
||||||
ParserInfoType = Dict
|
ParserInfoType = Dict
|
||||||
TimeStampFormatType = Dict
|
TimeStampFormatType = Dict
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
from pygments.token import (Name, Number, String, Keyword)
|
|
||||||
CustomColorType = Dict[Union[Name.Tag, Number, String, Keyword], str]
|
|
||||||
|
|
||||||
except Exception:
|
|
||||||
CustomColorType = Dict # type: ignore
|
|
||||||
|
Reference in New Issue
Block a user