@@ -59,16 +59,58 @@ namespace json
5959 * users to overwrite default options, while keeping any other ones.
6060 *
6161 * @param defaultValue A string containing either a JSON or a TOML dataset.
62+ * If the string begins with an `@`, the JSON/TOML dataset will be
63+ * read from the filesystem at the specified path.
6264 * @param overwrite A string containing either a JSON or TOML dataset (does
63- * not need to be the same as `defaultValue`).
65+ * not need to be the same as `defaultValue`).
66+ * If the string begins with an `@`, the JSON/TOML dataset will be
67+ * read from the filesystem at the specified path.
6468 * @return std::string The merged dataset, according to the above rules. If
65- * `defaultValue ` was a JSON dataset, then as a JSON string, otherwise as a
66- * TOML string.
69+ * `overwrite ` was a JSON dataset, then as a JSON string, otherwise
70+ * as a TOML string.
6771 */
6872 std::string
6973 merge (std::string const &defaultValue, std::string const &overwrite);
7074
7175#if openPMD_HAVE_MPI
76+ /* *
77+ * @brief Merge two JSON/TOML datasets into one.
78+ *
79+ * Merging rules:
80+ * 1. If both `defaultValue` and `overwrite` are JSON/TOML objects, then the
81+ * resulting JSON/TOML object will contain the union of both objects'
82+ * keys. If a key is specified in both objects, the values corresponding
83+ * to the key are merged recursively. Keys that point to a null value
84+ * after this procedure will be pruned.
85+ * 2. In any other case, the JSON/TOML dataset `defaultValue` is replaced in
86+ * its entirety with the JSON/TOML dataset `overwrite`.
87+ *
88+ * Note that item 2 means that datasets of different type will replace each
89+ * other without error.
90+ * It also means that array types will replace each other without any notion
91+ * of appending or merging.
92+ *
93+ * Possible use case:
94+ * An application uses openPMD-api and wants to do the following:
95+ * 1. Set some default backend options as JSON/TOML parameters.
96+ * 2. Let its users specify custom backend options additionally.
97+ *
98+ * By using the json::merge() function, this application can then allow
99+ * users to overwrite default options, while keeping any other ones.
100+ *
101+ * @param defaultValue A string containing either a JSON or a TOML dataset.
102+ * If the string begins with an `@`, the JSON/TOML dataset will be
103+ * read in parallel (using the MPI Communicator)
104+ * from the filesystem at the specified path.
105+ * @param overwrite A string containing either a JSON or TOML dataset (does
106+ * not need to be the same as `defaultValue`).
107+ * If the string begins with an `@`, the JSON/TOML dataset will be
108+ * read in parallel (using the MPI Communicator)
109+ * from the filesystem at the specified path.
110+ * @return std::string The merged dataset, according to the above rules. If
111+ * `overwrite` was a JSON dataset, then as a JSON string, otherwise
112+ * as a TOML string.
113+ */
72114 std::string merge (
73115 std::string const &defaultValue,
74116 std::string const &overwrite,
0 commit comments