Skip to content

Insufficient support for JSON path query. #72

@zaxbowow

Description

@zaxbowow

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions