Skip to content
This repository has been archived by the owner on May 15, 2019. It is now read-only.

JSON payload not being parsed correctly on Windows Shell #90

Closed
mrkevinze opened this issue Apr 28, 2017 · 7 comments
Closed

JSON payload not being parsed correctly on Windows Shell #90

mrkevinze opened this issue Apr 28, 2017 · 7 comments

Comments

@mrkevinze
Copy link

Description

Specifying an inline JSON payload will not work on a Windows shell if one follows the recommended CLI usage pattern. An error

"data" must be a valid JSON string!

is emitted.

The recommended CLI usage is
functions call helloWorld --data='{"foo":"bar"}'

The recommended command works fine when using Git Bash on Windows. However, it does not work when using the Google Cloud SDK Shell on Windows nor on the Windows Command Prompt; the aforementioned error will be thrown.

To see how the JSON is parsed, add console.log(process.argv); in the file /bin/functions. It becomes ''{foo:bar}'' which is indeed not valid JSON. It should be '{"foo":"bar"}' instead.

This problem may be related to #34 , but the problem is for call rather than deploy.

Steps to reproduce

Invoke functions call helloWorld --data='{"foo":"bar"}' using the Google Cloud SDK Shell on Windows or using the Windows Command Prompt.

Workaround

When using a Windows shell, call functions call helloWorld --data={\"foo\":\"bar\"} instead.
Note that this workaround is not compatible with Bash on Windows.

Thanks!

@jmdobry jmdobry closed this as completed in aa2a5cc May 1, 2017
@jmdobry
Copy link
Contributor

jmdobry commented May 1, 2017

I've updated the docs and the CLI's help text with Windows-specific instructions.

@jmdobry jmdobry self-assigned this May 1, 2017
@jmdobry jmdobry added this to Done in Docs May 1, 2017
@jmdobry jmdobry added this to Done in CLI May 1, 2017
@kmleow
Copy link

kmleow commented Sep 4, 2017

I have tried the backslash workaround, does not work. This is what I see with 1.0 alpha 25:
Error: "data" must be a valid JSON string!

I found out that I could instead do the following on Win 10:
functions call helloWorld --data '{\"foo\":\"bar\"}'

@jmdobry
Copy link
Contributor

jmdobry commented Sep 5, 2017

So on windows the surrounding single quotes are what made it work for you?

@kmleow
Copy link

kmleow commented Sep 5, 2017

@jmdobry yes, without equal (=) sign

@jmdobry
Copy link
Contributor

jmdobry commented Sep 6, 2017

I updated the docs, thanks.

@rijuvan
Copy link

rijuvan commented Mar 19, 2018

HI

It is still not working and I am getting below error

D:\gcp_demo\functionTraining\http>functions call helloWorld --data '{"message":"Hello, World"}'
Error: "data" must be a valid JSON string!
at Object.exports.handler.err [as handler] (C:\Users\Rijuvan.Ansari\AppData\Roaming\npm\node_mod
ules@google-cloud\functions-emulator\src\cli\commands\call.js:76:13)
at Object.runCommand (C:\Users\Rijuvan.Ansari\AppData\Roaming\npm\node_modules@google-cloud\fun
ctions-emulator\node_modules\yargs\lib\command.js:235:44)
at Object.parseArgs [as _parseArgs] (C:\Users\Rijuvan.Ansari\AppData\Roaming\npm\node_modules@g
oogle-cloud\functions-emulator\node_modules\yargs\yargs.js:1014:30)
at Object.parse (C:\Users\Rijuvan.Ansari\AppData\Roaming\npm\node_modules@google-cloud\function
s-emulator\node_modules\yargs\yargs.js:542:25)
at Object.main (C:\Users\Rijuvan.Ansari\AppData\Roaming\npm\node_modules@google-cloud\functions
-emulator\src\cli\main.js:69:6)
at getProjectId.then (C:\Users\Rijuvan.Ansari\AppData\Roaming\npm\node_modules@google-cloud\fun
ctions-emulator\bin\functions:104:27)
at process._tickCallback (internal/process/next_tick.js:109:7)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:383:7)
at startup (bootstrap_node.js:149:9)

Thanks in Advance !!

@chrisbeech
Copy link

It doesn't like the wrapping single quotes for me. This works:
functions call helloWorld --data "{\"message\":\"Hello World\"}"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
CLI
Done
Docs
Done
Development

No branches or pull requests

5 participants