.. index:: pair: namespace; json_utils .. _doxid-namespacejson__utils: namespace json_utils ==================== .. toctree:: :hidden: Overview ~~~~~~~~ .. ref-code-block:: cpp :class: doxyrest-overview-code-block namespace json_utils { // global functions :ref:`nlohmann::json` :ref:`parseJSONFile`(const std::string& fileName); void :ref:`jsonSchemaLoader`(const json_uri& uri, :ref:`json`& schema); void :ref:`validateJson`( :ref:`nlohmann::json`& instance, std::string schema_path, bool addPatch = true ); template static void :ref:`setDefault`( :ref:`nlohmann::json`& instance, const std::string key, const VALUE_T new_value ); } // namespace json_utils .. _details-namespacejson__utils: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Global Functions ---------------- .. index:: pair: function; parseJSONFile .. _doxid-namespacejson__utils_1a7d0b459799465e69c6f1478cb0186b8c: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`nlohmann::json` parseJSONFile(const std::string& fileName) Parse a JSON File and return it's values. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - fileName - File Name .. rubric:: Returns: Returns parsed JSON .. index:: pair: function; jsonSchemaLoader .. _doxid-namespacejson__utils_1a829b3b6bb93fbee27f28682be2097494: .. ref-code-block:: cpp :class: doxyrest-title-code-block void jsonSchemaLoader(const json_uri& uri, :ref:`json`& schema) Loads schema from json file given its uri. To be passed to a nlohmann::json_schema::json_validator constructor. The function is parametrized with two parameters: uri and schema. uri provides the path to the json schema within NRP_CONFIG_INSTALL_DIR directory. the schema will be loaded into "schema" json object. .. index:: pair: function; validateJson .. _doxid-namespacejson__utils_1a23cde5e08448362ad38c52b07011ade7: .. ref-code-block:: cpp :class: doxyrest-title-code-block void validateJson( :ref:`nlohmann::json`& instance, std::string schema_path, bool addPatch = true ) Validates a json object using a given json schema. Parameters: instance: json object to be validated schema_path: URI of the schema to use for validation addPatch: boolean attribute. If true, parameter default values defined in the schema are added to 'instance' after validation. .. index:: pair: function; setDefault .. _doxid-namespacejson__utils_1a64b4160cf91610a3976f135e1f880a92: .. ref-code-block:: cpp :class: doxyrest-title-code-block template static void setDefault( :ref:`nlohmann::json`& instance, const std::string key, const VALUE_T new_value ) Sets default value for a given parameter. The function is parametrized with three parameters: instance, key, new_value. A value 'new_value' for parameter 'key' is set in 'instance'. If 'key' already exists in 'instance' nothing is done