JSON Patch
Flavors use JSON Patch (RFC 6902) to modify configurations. This page explains the available operations.
JSON Patch Basics
Section titled “JSON Patch Basics”Each patch operation has:
- op - The operation type
- path - JSON Pointer to the target location
- value - The new value (for add/replace)
The Replace Operation
Section titled “The Replace Operation”Changes an existing value:
patches: - op: replace path: /env/NODE_ENV value: productionBefore:
env: NODE_ENV: developmentAfter:
env: NODE_ENV: productionNote: The path must exist. Replacing a non-existent path is an error.
The Add Operation
Section titled “The Add Operation”Adds a new property:
patches: - op: add path: /env/NEW_VAR value: "hello"Before:
env: NODE_ENV: developmentAfter:
env: NODE_ENV: development NEW_VAR: helloYou can also add to nested paths:
patches: - op: add path: /defaults/docker/buildArgs/VERSION value: "1.0.0"The Remove Operation
Section titled “The Remove Operation”Removes a property:
patches: - op: remove path: /env/DEBUGBefore:
env: NODE_ENV: development DEBUG: "true"After:
env: NODE_ENV: developmentJSON Pointer Syntax
Section titled “JSON Pointer Syntax”Paths use JSON Pointer format:
| Path | Target |
|---|---|
/env/NODE_ENV | config.env.NODE_ENV |
/defaults/docker/target | config.defaults.docker.target |
/components/api/resources/image/params/target | Deeply nested value |
Special characters in keys must be escaped:
~0for~~1for/
Multiple Patches
Section titled “Multiple Patches”Patches are applied in order:
flavors: production: patches: # First, change the environment - op: replace path: /env/NODE_ENV value: production
# Then, adjust logging - op: replace path: /env/LOG_LEVEL value: warn
# Finally, change the Docker target - op: replace path: /defaults/docker/target value: productionCommon Patterns
Section titled “Common Patterns”Change Docker Target
Section titled “Change Docker Target”- op: replace path: /defaults/docker/target value: productionSet Target Platform
Section titled “Set Target Platform”Build for a specific architecture (useful for CI/CD targeting production servers):
- op: add path: /defaults/docker/platform value: linux/amd64Common platform values: linux/amd64, linux/arm64, linux/arm/v7.
Add Build Arguments
Section titled “Add Build Arguments”- op: add path: /defaults/docker/buildArgs value: VERSION: "1.0.0" BUILD_DATE: "2024-01-01"Disable a Feature
Section titled “Disable a Feature”- op: replace path: /env/FEATURE_FLAG value: "false"Next Step
Section titled “Next Step”Continue to Using Flavors to see how to use flavors in practice.