4 Replies Latest reply on Jan 24, 2019 11:15 AM by csdibiase

    vcsa-deploy.exe JSON syntax validator broken on vCSA 6.7 media?

    schroedero_cp1 Novice

      I have a PowerShell script that I use to deploy vCSA. It generates the JSON template file for the vcsa-deploy.exe to use as an answer file.

       

      The JSON being produced has worked perfectly fine with the vcsa-deploy.exe file from vCSA 6.0 and 6.5 media.

       

      I tried today with the latest 6.7 media from the VMware-VCSA-all-6.7.0-10244745.iso and the syntax validator is tripping up all over the place.

       

      PowerShell by default escapes certain characters, such as the apostrophe, within a string value - it replaces it with a \u0027 - which is valid JSON. I know that the apostrophe does not need to be escaped since it is enclosed in double-quotes, but for some reason PowerShell decides to do it anyway. (I know how to make PowerShell not do that.) But the previous JSON syntax validator from 6.0 and 6.5 media had absolutely no issue with this escape sequence. The new syntax validator does not like the backslash and feels it should have been escaped itself.

       

      The other issue - and the one way more pressing - is that the JSON validator for 6.7 keeps failing a completely valid JSON file. It is being rejected because of the last closing curly bracket:

      Here is the error message:

      ====== [START] Start executing Task: To validate CLI options at 15:45:37 ======
      Command line arguments verfied.
       [SUCCEEDED] Successfully executed Task 'CLIOptionsValidationTask: Executing CLI
      optionsValidation task' in TaskFlow 'template_validation' at 15:45:37
      SyntaxValidationTask: Executing Template Syntax Validation task
       [START] Start executing Task: To validate the syntax of the template. at 15:45:37
      Template syntax validation failed for template
      C:\Users\OSCHRO~1\AppData\Local\Temp\vcsainstall-20181023-154534.json.
      Error: Redundant character. Cause: The character '}' on line 45 (character 1) is
      possibly redundant.  Resolution: Consider removing the character '}'.
      ================ [FAILED] Task: SyntaxValidationTask: Executing Template Syntax
      Validation task execution failed at 15:45:37 ================
      Task 'SyntaxValidationTask: Executing Template Syntax Validation task' execution
      failed because [Error: Redundant character. Cause: The character '}' on line 45
      (character 1) is possibly redundant. ], possible resolution is [Consider
      removing the character '}'.]

      The character the syntax validator is complaining about, is the very last curly bracket that needs to be there. I triple checked the JSON file to make sure I don't have an errand bracket, and it does not.

       

      To me this sounds like the syntax validator has a bug. Does anyone have any insight?

        • 2. Re: vcsa-deploy.exe JSON syntax validator broken on vCSA 6.7 media?
          schroedero_cp1 Novice

          JSONLint also confirmed that the file is valid JSON.

          • 3. Re: vcsa-deploy.exe JSON syntax validator broken on vCSA 6.7 media?
            schroedero_cp1 Novice

            The problem ended up being that PowerShell creates a UTF-8 JSON file with a BOM. If I modify the PowerShell script to output a JSON file in UTF-8 format without BOM, the syntax validator works as intended and also does not complain about escaped characters. Whether the line endings are CRLF or LF does apparently not matter. The existence of the BOM was no issue in the vCSA deploy binary with v6.5.

            2 people found this helpful
            • 4. Re: vcsa-deploy.exe JSON syntax validator broken on vCSA 6.7 media?
              csdibiase Novice

              Just to add to this discussion for the benefit of others, I didn't find creating a json file in UTF-8 without the byte order manifest (BOM) to be that trivial to figure, but I'm not the PowerShell wizard that others are yet.

               

              I did piece together tips on a few stack exchange threads and come up with the following 3 line to export the config.json from my script:

               

              # convert the PowerShell hash table used in the script back to json format, correcting for PowerShell's love of overescaping characters and

              # out of paranoia switching from CRLF to LF for EOL to match the template's original format

              $configJsonText = (ConvertTo-Json $configJson | ForEach-Object { [System.Text.RegularExpressions.Regex]::Unescape($_) }) -replace "`r`n", "`n"  
              # Set the UTF8 encoding to not include the BOM  
              $utf8NoBOM = New-Object System.Text.UTF8Encoding $false  
              # Actually write the file 
              [System.IO.File]::WriteAllText($configJsonPath,$configJsonText,$utf8NoBOM)
              In my case the cli installer was returning:
              2019-01-18 19:49:02,995 - vCSACliInstallLogger - DEBUG - Task 'SyntaxValidationTask: Executing Template Syntax Validation task' execution failed because [Error: Redundant character. Cause: The character '}' on line 45 (character 1) is possibly redundant. ], possible resolution is [Consider removing the character '}'.]
              VMware must have changed something in the JSON library they used then failed to test it with PowerShell based scripts. Either it's more strictly adhering to RFC 7159, or its just choking on the first line of the JSON and skipping it if it has a BOM in it. Based on the error complaining about an extra brace on the last line of the file I think the later is probably the change in behavior.
              1 person found this helpful