<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _create_get_state_request(self, given_devices):
 """Create state request."""

        dev_list = []

        if isinstance(given_devices, list):
            devices = given_devices
        else:
            devices = []
            for dev_name, item in self.__devices.items():
                if item:
                    devices.append(self.__devices[dev_name])

        for device in devices:
            states = []

            for state_name in sorted(device.active_states.keys()):
                states.append({'name': state_name})

            dev_list.append({'deviceURL': device.url, 'states': states})

        return json.dumps(
            dev_list, indent=None,
            sort_keys=True, separators=(',', ': '))