Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insufficient support for JSON path query. #72

Open
zaxbowow opened this issue Mar 8, 2024 · 0 comments
Open

Insufficient support for JSON path query. #72

zaxbowow opened this issue Mar 8, 2024 · 0 comments

Comments

@zaxbowow
Copy link

zaxbowow commented Mar 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant