tlc.core.json_helper
#
Utility class for JSON manipulation
Module Contents#
Classes#
Class |
Description |
---|---|
A class with helper methods for working with JSON strings |
API#
- class tlc.core.json_helper.JsonHelper#
A class with helper methods for working with JSON strings
- static sort_by_rank(data: dict[str, Any], rankings: list[tuple[str, int]], default_rank: int = 0) dict[str, Any] #
Helper to (stable) sort a dictionary based on input ranks.
Given a list of tuples with keys and their rank, sort the dictionary such that the items with lowest rank appear first.
Lower rank items are sorted before higher rank items.
If a key is not found in the rank list, it is assigned the default_rank.
Add a key with a negative rank to sort it before the default_rank.
All keys with the same rank are sorted based on order in the input dictionary.
Only top-level keys are sorted. Nested keys are not sorted.