Unable to print string containing double quotes in GitLab CI YAML

I made it work like this:

  script: |
   "EXPECT_SERVER_OUTPUT='{\"message\": \"Hello World\"}'"
   echo $EXPECT_SERVER_OUTPUT

You could use literal block scalar1 style notation and put the variable definition and subsequent script lines on separate lines2 without worrying about quoting:

myjob:
  script:
    - |
      EXPECT_SERVER_OUTPUT='{"message": "Hello World"}'

or you can escape the nested double quotes:

myjob:
  script:
    - "EXPECT_SERVER_OUTPUT='{\"message\": \"Hello World\"}'"

but you may also want to just use variables like:

myjob:
  variables:
    EXPECT_SERVER_OUTPUT: '{"message": "Hello World"}'
  script:
    - dothething.sh

Note: variables are expanded inside variable definitions so take care with any $ characters inside the variable value (they must be written as $$ to be literal).

1See this answer for an explanation of this and related notation
2See this section of the GitLab docs for more info on multi-line commands