pnoltes commented on code in PR #743:
URL: https://github.com/apache/celix/pull/743#discussion_r1570050484


##########
libs/utils/include/celix_properties.h:
##########
@@ -936,6 +936,348 @@ CELIX_UTILS_EXPORT bool 
celix_propertiesIterator_equals(const celix_properties_i
          !celix_propertiesIterator_isEnd(&(iterName));                         
                                        \
          celix_propertiesIterator_next(&(iterName)))
 
+/**
+ * @brief Flag to indicate that the encoded output should be pretty; e.g. 
encoded with additional whitespaces,
+ * newlines and indentation.
+ *
+ * If this flag is not set, the encoded output will compact; e.g. without 
additional whitespaces, newlines and
+ * indentation.
+ */
+#define CELIX_PROPERTIES_ENCODE_PRETTY 0x01
+
+/**
+ * @brief Flag to indicate that the encoded output should be flat; e.g. all 
properties entries are written as top level
+ * field entries.
+ *
+ * E.g:
+ * @code{.c}
+ * celix_properties_t* properties = celix_properties_create();
+ * celix_properties_setString(properties, "key/with/slash", "value1");
+ * celix_properties_setString(properties, "key", "value2");
+ * char* json;
+ * celix_properties_saveToString(properties, CELIX_PROPERTIES_ENCODE_FLAT, 
&json);
+ * // json will be: {"key/with/slash": "value1", "key": "value2"}
+ * @endcode
+ *
+ * Note that encoding with a flat encoding style, all properties keys are 
unique JSON keys and can be written.
+ *
+ * If no encoding style flag is set, the encoded output will use the default 
encoding style.
+ */
+#define CELIX_PROPERTIES_ENCODE_FLAT_STYLE 0x02
+
+/**
+ * @brief Flag to indicate that the encoded output should be nested; e.g. 
properties entries are split on '/' and nested

Review Comment:
   Good point. My train of thought was that in the future we maybe could do 
something with properties and JPath 
(https://www.ibm.com/docs/en/dsm?topic=protocol-jpath). Not something actually 
planned, but more an option to keep open. 
   
   e.g. something like:
   ```
   long value = celix_properties_queryLong(props, "/root/field/array[2]", -1); 
//select 3rd element from long array (if the fields, array, array element 
exists)
   //or 
   const char* str = celix_properties_queryString(props, "/root/field[exists 
@otherField]/name"); //query for /root/field/name, but only if a 
/root/field/otherField exists
   ```
   
   But on the other hand there is also something like JsonPath 
(https://datatracker.ietf.org/doc/rfc9535/) which uses a dot oriented path 
notation. e.g.:
   ```
   long value = celix_properties_queryLong(props, "$.root.field.array[2]", -1);
   //etc
   ```
   
   I personally prefer the JPath syntax, but seeing that JsonPath is (or is 
becoming?) a IETF RFC, I will change the separator to `.` instead of `/`. 
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@celix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to