GitHub Actions Invalid JSON syntax in workflow

The workflow file contains invalid JSON syntax.

Understanding GitHub Actions

GitHub Actions is a powerful CI/CD tool that allows developers to automate their software workflows directly from their GitHub repositories. It enables users to build, test, and deploy code right from GitHub. With GitHub Actions, you can create workflows that are triggered by GitHub events such as push, pull requests, or on a schedule.

Identifying the Symptom

When working with GitHub Actions, you might encounter an error message indicating 'Invalid JSON syntax in workflow'. This error typically appears in the GitHub Actions logs when the workflow file contains syntax errors, preventing the workflow from executing correctly.

Common Error Message

The error message might look something like this:

Error: Invalid JSON syntax in workflow file: .github/workflows/main.yml

Details About the Issue

The 'Invalid JSON syntax in workflow' error occurs when the JSON structure within the workflow file is not correctly formatted. This could be due to missing commas, incorrect brackets, or other syntax issues that violate JSON standards. Although GitHub Actions primarily uses YAML for workflow files, JSON syntax errors can occur if JSON is embedded or improperly converted.

Why This Happens

This issue often arises when:

  • There are missing or extra commas in JSON objects.
  • Brackets are not properly closed.
  • Strings are not enclosed in double quotes.
  • There are trailing commas in JSON arrays or objects.

Steps to Fix the Issue

To resolve the 'Invalid JSON syntax in workflow' error, follow these steps:

Step 1: Validate JSON Syntax

Use an online JSON validator such as JSONLint to check your JSON syntax. Copy and paste your JSON content into the validator to identify and correct syntax errors.

Step 2: Check for Common Mistakes

  • Ensure all JSON objects are enclosed in curly braces {}.
  • Verify that all keys and string values are enclosed in double quotes "".
  • Remove any trailing commas from JSON objects and arrays.

Step 3: Use a JSON Formatter

Consider using a JSON formatter to automatically format your JSON code. Tools like JSON Formatter can help ensure your JSON is properly structured.

Conclusion

By following these steps, you should be able to resolve the 'Invalid JSON syntax in workflow' error in your GitHub Actions workflow file. Ensuring your JSON is correctly formatted is crucial for the successful execution of your workflows. For more information on GitHub Actions, visit the official GitHub Actions documentation.

Master

GitHub Actions

in Minutes — Grab the Ultimate Cheatsheet

(Perfect for DevOps & SREs)

Most-used commands
Real-world configs/examples
Handy troubleshooting shortcuts
Your email is safe with us. No spam, ever.

Thankyou for your submission

We have sent the cheatsheet on your email!
Oops! Something went wrong while submitting the form.

GitHub Actions

Cheatsheet

(Perfect for DevOps & SREs)

Most-used commands
Your email is safe with us. No spam, ever.

Thankyou for your submission

We have sent the cheatsheet on your email!
Oops! Something went wrong while submitting the form.

MORE ISSUES

Made with ❤️ in Bangalore & San Francisco 🏢

Doctor Droid