Skip to content

Conversation

JoeyShapiro
Copy link

I am trying to create a key in an object like this

{
    "events(24hrs)": 3,
    "event": 3
}

I have to use the parens because of supporting legacy code.

However, when I do this with wjelement, I get an object with NULL. The key events(24hrs) or its value are never added to the object. I did some digging in the code and found out that this is caused by an alnumx check for each key. If the key is invalid, it bails and returns NULL.

The JSON interchange format is specified in RFC 7159. Section 4 says an object's "name" is a string, and Section 7 for strings gives a grammar for them to follow. They are a few rules for escaping certain characters, but most are allowed just as they are. In my case, the parens.

I tried to implement a new check to allow this, which is the subject of my Pull Request, and it works for my case just fine. However, I noticed that when you use WJEInt32 it is not asking for the key, but the path of the key. This means there is some advanced logic for characters like [].*/ and so on. So I do not think my idea will not properly work.

So I am wondering if you have a better idea, or are willing to help me think through a solution. Maybe add a function for using key instead of path, even though path would still have the problem of not supporting some characters.

I can implement this as a feature, I just really need your approval, and any ideas you have about this.

@penduin
Copy link
Member

penduin commented Sep 5, 2025 via email

@JoeyShapiro
Copy link
Author

could you give an example of how I could use WJEChild. I couldn't find anything on it. I need it to be something like WJEInt32

@penduin
Copy link
Member

penduin commented Sep 5, 2025 via email

@JoeyShapiro
Copy link
Author

so yeah, I can do something like WJEInt32(WJEChild(obj, "name()", WJE_SET), NULL, WJE_SET, 3);
a little cumbersome, but it does allow more characters in the name.

the path does not allow all characters, and some are used for the path processing.

@minego
Copy link
Member

minego commented Sep 8, 2025 via email

@JoeyShapiro
Copy link
Author

alright, that is understandable, and I totally see the awkwardness it leads to. I can close my PR, unless you want to create a new set of functions that take the name instead of path.

@minego
Copy link
Member

minego commented Sep 8, 2025 via email

@JoeyShapiro
Copy link
Author

I'm also debating allowing more characters to be used. currently you can only use characters in a path name that pass alnumx but only a handful of characters are keywords for the path.

maybe allow any character, and if you want to do path processing, then you need to escape it, or something.

I'm not sure if the path ones should be left alone, and only add new functions for non path parameters. And if the path versions are modified, do we have to worry about backwards compatibility

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

Successfully merging this pull request may close these issues.

3 participants