def parse_response(self, response, command_list):
        '''
        Parse NX-API JSON response from the NX-OS device.
        '''
        # Check for 500 level NX-API Server Errors
        if isinstance(response, collections.Iterable) and 'status' in response:
            if int(response['status']) >= 500:
                raise NxosError('{}'.format(response))
            else:
                raise NxosError('NX-API Request Not Supported: {}'.format(response))

        if isinstance(response, collections.Iterable):
            body = response['dict']
        else:
            body = response

        if self.nxargs['connect_over_uds']:
            body = json.loads(response.read().decode('utf-8'))

        # Proceed with caution.  The JSON may not be complete.
        # Don't just return body['ins_api']['outputs']['output'] directly.
        output = body.get('ins_api')
        if output is None:
            raise NxosClientError('Unexpected JSON output\n{0}'.format(body))
        if output.get('outputs'):
            output = output['outputs']
        if output.get('output'):
            output = output['output']

        # The result list stores results for each command that was sent to
        # nxapi.
        result = []
        # Keep track of successful commands using previous_commands list so
        # they can be displayed if a specific command fails in a chain of
        # commands.
        previous_commands = []

        # Make sure output and command_list lists to be processed in the
        # subesequent loop.
        if not isinstance(output, list):
            output = [output]
        if isinstance(command_list, string_types):
            command_list = [cmd.strip() for cmd in command_list.split(';')]
        if not isinstance(command_list, list):
            command_list = [command_list]

        for cmd_result, cmd in zip(output, command_list):
            code = cmd_result.get('code')
            msg = cmd_result.get('msg')
            log.info('command %s:', cmd)
            log.info('PARSE_RESPONSE: %s %s', code, msg)
            if code == '400':
                raise CommandExecutionError({
                    'rejected_input': cmd,
                    'code': code,
                    'message': msg,
                    'cli_error': cmd_result.get('clierror'),
                    'previous_commands': previous_commands,
                })
            elif code == '413':
                raise NxosRequestNotSupported('Error 413: {}'.format(msg))
            elif code != '200':
                raise NxosError('Unknown Error: {}, Code: {}'.format(msg, code))
            else:
                previous_commands.append(cmd)
                result.append(cmd_result['body'])

        return result
Parse NX-API JSON response from the NX-OS device.