import json
from typing import Union
[docs]
def json_to_int_list(json_input: Union[str, list]) -> list[int]:
"""
Converts a JSON string or a list of integers into a list of integers.
Parameters:
json_input (Union[str, list]): A JSON string representing a list of integers or a list of integers.
Returns:
list[int]: A list of integers extracted from the JSON input.
"""
if isinstance(json_input, str):
try:
data = json.loads(json_input)
except json.JSONDecodeError as e:
raise ValueError("Invalid JSON string") from e
elif isinstance(json_input, list):
data = json_input
return [int(item) for item in data]