At AcmeCLI, you need to format an API response into a deterministic, aligned text table.
Implement format_api_output(response_json, query, sort_by, limit).
response_json: str — JSON string expected to be an array of objects.query: str — case-insensitive substring filter applied to name.sort_by: str — either 'name' or 'score'.limit: int — maximum number of output rows.id and name are strings.score handling:
null, treat as 0.int (but not bool); otherwise ignore the record.sort_by == 'name': sort by name.lower() ascending, then id ascending.sort_by == 'score': sort by score descending, then name.lower() ascending, then id ascending.ID NAME SCORE.ID and NAME are left-aligned; SCORE is right-aligned.response_json='[{"id":"1","name":"A","score":"9"},{"id":"2","name":"A","score":9}]', query='', sort_by='score', limit=10
Output:
ID NAME SCORE 2 A 9
Explanation: the first record is ignored because score is a string.
response_json='[{"id":"x","name":"Echo"},{"id":"y","name":"echelon","score":0},{"id":"z","name":"Other","score":5}]', query='ech', sort_by='name', limit=10
Output:
ID NAME SCORE x Echo 0 y echelon 0
Explanation: filter keeps Echo/echelon; sort is case-insensitive by name.
0 <= len(response_json) <= 2 * 10^60 <= n <= 2 * 10^5 (records in parsed array)0 <= limit <= nsort_by in {'name','score'}