Given a complex, nested JSON payload from a mock API, write a script to flatten the data, apply specific transformation rules, and output it to a structured format.
Implement def flatten_payload(payload):, accepting a JSON-compatible dictionary or list and returning a list of dictionaries with path and value fields. Recursively flatten dictionaries and lists using dot-separated paths with zero-based array indexes, omit null-valued leaves, trim strings, and convert booleans to lowercase strings. Return records in deterministic depth-first order.
def flatten_payload(payload):