Value Resource
Synopsis
Manages JSON values at specific JSONPath locations within JSON files. Supports setting, reading, and removing values of any JSON type (string, number, boolean, null, object, or array). Parent paths are created recursively when they don't exist.
Type
Capabilities
- Get
- Set
- Delete
Properties
path
Absolute file path to the JSON document.
jsonPath
JSONPath expression to locate the value. Must start with $.
value
JSON value to set. Can be a string, number, boolean, null, object, or array.
_exist
Whether the value should exist.
Examples
Example 1 — Get a value
Example 2 — Set a string value
Example 3 — Set an object value
Example 4 — Delete a value
Example 5 — Configuration document
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Set application log level
type: OpenDsc.Json/Value
properties:
path: /opt/myapp/config.json
jsonPath: $.logging.level
value: Warning
- name: Set connection string
type: OpenDsc.Json/Value
properties:
path: /opt/myapp/config.json
jsonPath: $.connectionStrings.default
value: "Host=db.example.com;Database=app;Username=appuser"
Exit codes
| Code | Description |
|---|---|
| 0 | Success |
| 1 | Error |
| 2 | Invalid JSON |
| 3 | JSON file not found |
| 4 | Invalid argument |
| 5 | IO error |