Need help with your JSON?
Try our JSON Formatter tool to automatically identify and fix syntax errors in your JSON. JSON Formatter tool
GitOps Workflows for JSON Configuration Files
GitOps is an operational framework that takes DevOps best practices like version control, collaboration, compliance, and CI/CD and applies them to infrastructure automation. It aims to manage your infrastructure and applications using Git as the single source of truth. While often associated with YAML configuration in Kubernetes, GitOps principles are equally applicable to managing other configuration formats, including JSON configuration files.
This page explores how to effectively leverage GitOps workflows when your application or infrastructure configuration is defined in JSON.
What is GitOps (Briefly)?
At its core, GitOps relies on four principles:
- Declarative Configuration: The desired state of the system (infrastructure, applications, configuration) is declared in a format that can be version-controlled (e.g., JSON, YAML, HCL).
- Version Control (Git): The declarative configuration is stored in Git, serving as the single source of truth and providing a complete history of changes.
- Automated Reconciliation: Agents or controllers continuously observe the actual state of the system and compare it to the desired state declared in Git. If discrepancies are found, the agent automatically reconciles the actual state to match the desired state.
- Pull Requests for Operations: All changes to the desired state are made via Pull Requests (PRs) to the Git repository. This enables collaboration, review, and approval workflows before changes are applied.
JSON as Configuration Format
JSON (JavaScript Object Notation) is a lightweight and widely used data interchange format. It's frequently used for:
- Application settings (feature flags, API endpoints, database credentials)
- Microservice configuration
- Configuration for specific tools and libraries
- Data schemas
While less common for infrastructure declarations compared to YAML in Kubernetes contexts, JSON remains prevalent for application-level configuration. Integrating these JSON configuration files into a GitOps workflow provides the same benefits: versioning, audit trails, rollback capabilities, and a collaborative, review-driven process for managing changes.
The GitOps Workflow with JSON
Applying GitOps to JSON configuration follows the standard GitOps pattern, with the focus on the JSON files themselves.
1. Change the Desired State (Modify JSON)
Instead of directly modifying configuration on servers or through dashboards, you modify the JSON file(s) in your Git repository that define the desired state.
Example: Modifying a feature flag JSON file
Before:
{
"featureFlags": {
"newDashboard": false,
"enableAnalytics": true
},
"apiEndpoint": "https://api.example.com/v1"
}
After (Desired State):
{
"featureFlags": {
"newDashboard": true, /* Enabled new dashboard */
"enableAnalytics": true
},
"apiEndpoint": "https://api.example.com/v1"
}
You make these changes on a new Git branch.
2. Create a Pull Request (PR)
Once the changes to the JSON file(s) are committed to your branch, you open a Pull Request against the main branch (e.g., "main"
, "master"
, "production"
). This is the core of the GitOps workflow for changes.
The PR serves as a notification and collaboration point:
- It clearly shows the diff of the JSON changes.
- Teammates can review the proposed configuration change.
- Automated checks (CI) can run against the changes.
3. Review and Approve
Peers review the PR, just like code. They examine the JSON changes to ensure they are correct, adhere to standards, and won't cause unintended side effects. Automated checks can include:
- JSON schema validation to ensure the structure and data types are correct.
- Linting to check for syntax errors or style issues.
- Impact analysis (if possible) to understand what systems or features the configuration change affects.
Once reviewed and approved, the PR is merged into the main branch.
4. Automate Deployment/Synchronization
This is where the "Ops" part of GitOps shines. An automated process or agent monitors the main Git branch. When a change is detected (a merge), it triggers a synchronization mechanism.
For JSON configuration, this could involve:
- A CI/CD pipeline that pulls the latest config from Git and deploys it (e.g., updates a ConfigMap in Kubernetes, pushes to a configuration service, restarts an application with the new config).
- A dedicated GitOps agent (like Argo CD, Flux, or a custom script) that detects the change in the JSON file in Git and applies it to the target system where the configuration is consumed.
The key is that the change is propagated automatically based on the Git state, without manual intervention after the merge.
Summary of Flow:
Git Repository (JSON files) | | (1) Developer/Operator makes change on branch v New Branch with JSON modifications | | (2) Create Pull Request v Pull Request (Diff: JSON changes) | | (3) Automated Checks (Schema, Lint) + Team Review & Approve v Merge to main branch | | (4) Automated Sync Triggered by Git change v Target System (Application/Service) fetches/receives new JSON config | | (Automated Reconciliation - Agent observes & corrects if needed) v Actual State matches Desired State (defined in Git JSON)
Tools and Techniques
Implementing GitOps for JSON config can involve several tools:
- Git: Essential for version control and the PR workflow.
- CI/CD Platform: Jenkins, GitHub Actions, GitLab CI, CircleCI, etc., to automate validation (linting, schema checks) and the deployment/sync process triggered by Git changes.
- JSON Schema Validation: Tools like
"ajv"
(JavaScript),"jsonschema"
(Python), or integrating schema validation into your CI pipeline ensures configuration files adhere to a predefined structure.Example Schema Check (Conceptual CI Step):
npm install -g ajv-cli # or equivalent for your language ajv validate -s config.schema.json -d app-config.json
- Configuration Management Tools: Depending on where the JSON config is consumed, tools like Ansible, Chef, Puppet, or custom scripts can be used by the automated sync process to place or update the JSON file on target systems.
- Kubernetes ConfigMaps/Secrets: If deploying to Kubernetes, JSON config can be embedded within ConfigMaps or Secrets, which are then managed using a GitOps controller like Argo CD or Flux.
Example Kubernetes ConfigMap embedding JSON:
apiVersion: v1 kind: ConfigMap metadata: name: app-settings data: settings.json: | { "database": { "host": "localhost", "port": 5432 }, "logging": { "level": "info" } }
- GitOps Controllers: Argo CD or Flux can monitor a Git repository containing JSON files (perhaps embedded in ConfigMaps) and automatically synchronize the cluster state.
Best Practices
- Schema Validation: Always define and validate your JSON configuration against a schema in your CI pipeline. This catches errors before they reach production.
- Small, Atomic Commits/PRs: Make changes in small, logical units. Each PR should ideally address a single configuration change. This makes reviews easier and reduces risk.
- Environment-Specific Configuration: Manage configurations for different environments (dev, staging, prod) clearly. This could be done with separate files, separate directories, or templating/overlay tools if necessary (though keep it simple for pure JSON).
Example Directory Structure:
config/ development/ app-settings.json staging/ app-settings.json production/ app-settings.json
- Sensitive Data: JSON files in Git should generally NOT contain secrets (passwords, API keys, etc.). Use secret management systems (like Vault, AWS Secrets Manager, Kubernetes Secrets with encryption) and reference secrets in your configuration instead of embedding them directly.
- Automation: Automate as much of the process as possible: validation, deployment, monitoring the actual state.
- Audit Trail: Git provides an inherent audit trail of who changed what and when, for every configuration change.
- Rollbacks: Need to revert a bad configuration change? Simply revert the merge commit or the specific commit in Git, and the automated sync process will roll back the configuration on the target system.
Example JSON Configuration File (Conceptual)
Let's imagine a simple application configuration file managed via GitOps.
{
"applicationName": "MyAwesomeApp",
"version": "1.2.0",
"settings": {
"theme": "dark",
"language": "en-US",
"itemsPerPage": 25
},
"services": {
"userService": {
"url": "https://users.example.com/api",
"timeoutMs": 5000
},
"productService": {
"url": "https://products.example.com/api",
"timeoutMs": 8000
}
},
"featureFlags": {
"enableRecommendations": true,
"useNewCheckoutFlow": false
}
}
Any change to this file (e.g., changing "theme": "dark"
to "light"
, or "useNewCheckoutFlow": false
to "true"
) would go through the PR, review, merge, and automated synchronization process defined by your GitOps setup.
Conclusion
GitOps provides a robust and reliable way to manage application and infrastructure configuration. By treating JSON configuration files as declarative desired states stored in Git and automating the reconciliation process, teams can achieve greater consistency, traceability, and efficiency in their operations. Whether you are managing application settings, service endpoints, or feature flags defined in JSON, adopting a GitOps workflow ensures that changes are collaborative, reviewed, validated, and automatically applied, bringing configuration management into a modern, version-controlled paradigm.
Need help with your JSON?
Try our JSON Formatter tool to automatically identify and fix syntax errors in your JSON. JSON Formatter tool