import json


def GetErrorMessage(stdout):
  """Extract a message field from JSON output if present."""
  try:
    return json.loads(stdout)['message']
  except (ValueError, KeyError):
    return stdout