JSON Config: Difference between revisions
Jump to navigation
Jump to search
m (change yaml to json) |
|||
(7 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<!-- JSON_Config.mediawiki --> | |||
This block... | This block presents a JSON config file which is read in as a dictionary. | ||
The values can be used directly when instantiating blocks. For example, | |||
Sample Rate: json_config["samp_rate"] | |||
Optionally, a JSON schema can be specified to validate the configuration. | |||
For example, you could have a JSON file that contains: | |||
<nowiki> | |||
{ | |||
"samp_rate": 1e6, | |||
}</nowiki> | |||
And a schema that contains | |||
<nowiki> | |||
{ | |||
"type": "object", | |||
"properties": { | |||
"samp_rate": {"type": "number", "exclusiveMinimum": 0} | |||
} | |||
}</nowiki> | |||
If the id of this block is <code>json_config_0</code>, then you can access the samp rate | |||
in other blocks as <code>json_config_0["samp_rate"]</code>. | |||
== Parameters == | == Parameters == | ||
; Config File | ; Config File | ||
: | : File name of the JSON config file | ||
; Config Schema | ; Config Schema | ||
: (Optional) | : (Optional) File name of the JSON schema file | ||
== Example Flowgraph == | == Example Flowgraph == | ||
The <code>example.json</code> file contains: | |||
<pre> | <pre> | ||
{ | |||
"amplitude": 0.1, | |||
"frequency": 1000 | |||
} | |||
</pre> | </pre> | ||
[[File:Json_config_example_prop.png]] | |||
[[File: | |||
[[File: | [[File:Json_config_example_fg.png]] | ||
== Example Output == | |||
[[File: | [[File:Json_config_example_out.png]] | ||
== Source Files == | == Source Files == | ||
; Block definition | |||
: [https://github.com/gnuradio/gnuradio/blob/main/grc/blocks/json_config.block.yml json_config.block.yml] | |||
[[Category:Block Docs]] | |||
Latest revision as of 10:57, 20 June 2023
This block presents a JSON config file which is read in as a dictionary.
The values can be used directly when instantiating blocks. For example, Sample Rate: json_config["samp_rate"]
Optionally, a JSON schema can be specified to validate the configuration.
For example, you could have a JSON file that contains:
{ "samp_rate": 1e6, }
And a schema that contains
{ "type": "object", "properties": { "samp_rate": {"type": "number", "exclusiveMinimum": 0} } }
If the id of this block is json_config_0
, then you can access the samp rate
in other blocks as json_config_0["samp_rate"]
.
Parameters
- Config File
- File name of the JSON config file
- Config Schema
- (Optional) File name of the JSON schema file
Example Flowgraph
The example.json
file contains:
{ "amplitude": 0.1, "frequency": 1000 }
Example Output
Source Files
- Block definition
- json_config.block.yml