mjson icon indicating copy to clipboard operation
mjson copied to clipboard

Insufficient support for JSON path query.

Open zaxbowow opened this issue 1 year ago • 0 comments

The very nice mjson library really needs to support json fields with spaces in their names. For example, consider the following valid json:

{
  "translations": {
    "expression with spaces": {
      "fr": "Translation of Expression1 in French",
      "es": "Translation of Expression1 in Spanish",
      "de": "Translation of Expression1 in German"
    }
  }
}

The following JSONpath statements are valid to perform a lookup:

$.["translations"]["expression with spaces"]["fr"]
$.translations."expression with spaces".fr

But none will work in mjson:

    const char *s = \
    "{"
      "\"translations\": {"
        "\"expression with spaces\": {"
          "\"fr\": \"Translation of Expression1 in French\","
          "\"es\": \"Translation of Expression1 in Spanish\","
          "\"de\": \"Translation of Expression1 in German\""
        "}"
      "}"
    "}\"";
    
    const char *xp = "$.translations.\"expression with spaces\".fr";
    
    char *p;
    int m;
    int n = mjson_find(s, strlen(s), xp, &p, &m);

mjson_find will always return zero.

As such, there is no way to construct a JSONpath statement to query JSON objects that contain spaces in their names using mjson. This is a trivial JSONpath statement, no fancy functions here.

zaxbowow avatar Mar 08 '24 23:03 zaxbowow