2

I want to specify a windows file path in my remote-ftp Atom configuration to reference my private key but I get some parsing issues. Here's my configuration:

{
    "protocol": "sftp",
    "host": "somehost.com",
    "port": 22,
    "user": "haha",
    "pass": "testpass",
    "promptForPass": false,
    "remote": "/",
    "local": "",
    "agent": "",
    "privatekey": "C:\Users\haha\Documents\Keys\test_private_key.ppk",
    "passphrase": "",
    "hosthash": "",
    "ignorehost": true,
    "connTimeout": 10000,
    "keepalive": 10000,
    "keyboardInteractive": false,
    "keyboardInteractiveForPass": false,
    "remoteCommand": "",
    "remoteShell": "",
    "watch": [],
    "watchTimeout": 500
}

With the error:

Parse Error: "privatekey": "C:\Users\haha\Docum

So any idea how i escape Windows file paths for JSON parsing?

snakespan
  • 1,183
  • 2
  • 15
  • 33
  • 1
    I forget, but it may be a problem with the backslashes. Try putting \\ everywhere that you have \ and see if the issue persists. – StardustGogeta Jul 23 '19 at 13:18
  • When I do this, I get 'unexpected token "h" at position 268' (the start of haha in that line) – snakespan Jul 23 '19 at 13:22
  • Can you copy-paste that entire line here, with the error message you are getting? There may just be a simple typo somewhere. – StardustGogeta Jul 23 '19 at 13:24
  • `"privatekey": "C:\\Users\\haha\\Documents\\Keys\\test_private_key.ppk",` should be all you need to do, – Alex K. Jul 23 '19 at 13:25
  • ```"privatekey": "C:\\Users\\haha\\Documents\\Keys\\test_private_key.ppk",``` Unexpected token h in JSON at position 268 – snakespan Jul 23 '19 at 13:27
  • Thank you! That looks right to me. Are you absolutely sure that you are looking at the correct line and position? If so, why is the position so high? (>200) – StardustGogeta Jul 23 '19 at 13:31
  • 1
    Yes I'm absolutely sure. However, I've found a question which may be related and it could be an Atom specific problem - https://stackoverflow.com/questions/51152008/issue-connection-to-server-using-remote-ftp-atom-package-and-private-keys as it appears you need your private key accessible in Window app data – snakespan Jul 23 '19 at 13:34
  • Good find, that may be the same problem. – StardustGogeta Jul 23 '19 at 13:41

1 Answers1

4

Your JSON is invalid, since backslashes need to be escaped per spec.

A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes

Hence, the value of privateKey should be "C:\\Users\\haha\\Documents\\Keys\\test_private_key.ppk".

idleberg
  • 12,634
  • 7
  • 43
  • 70