returning json output in stdout from fly machine

i am making a req to the fly machine where i run a bash script like sh ./

the script file returns data in json structure

 if [ "$output" = "$expected_output" ]; then
          # Output matches expected result
          json_output="{ \"state\": \"pass\", \"output\": \"$output\" }"
          # Output does not match expected result
          json_output="{ \"state\": \"fail\", \"output\": \"$output\" }"
        # Print JSON output
        echo "$json_output"

However when this json is returned from fly machine, I dont get valid json anymore inside stdout.

"{\"stdout\":\"{ state: fail, output: some-text }\\n\",\"stderr\":\"\",\"exit_code\":0,\"exit_signal\":0}"

Quotes did get elided there… (E.g., state should be \\\"state\\\"—for those (like me) who didn’t spot it immediately.)

Have you tried reducing this to a smaller and more obvious script? For example,

echo '"x"'

It would probably also help to provide the exact details of how you’re making these requests and printing the results.

1 Like

this is solved. i had to do a printf to keep the valid json state.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.