Open jnnwnk opened 4 years ago
Since there was no feedback so far, I created a fork (for now). So far only the mapping camelCase
<-> PascalCase
(which we currently need) is implemented: https://github.com/jnnwnk/JsonLogic.Net
If someone is interested: Feedback is appreciated. The changes can be extended if necessary and converted into a pull request.
Sorry for the slow response @jnnwnk . I am having some trouble with github notifications. I will work on merging your pull request if you create one.
Why not alter the data itself on the backend side prior to running the evaluator? You can use Newtonsoft contract resolver to turn your payload into the correctly named data packet matching your client? If you have data object classes, you can decorate them with the correct naming strategy?
An ugly way of doing this is to just take your data string (or object, in which case drop half of this code) and do:
var dataString = "{ \"MyProperty\": [1, 2, 3, 4] }";
var jsonIn = JToken.Parse(dataString);
dynamic objIn = JsonConvert.DeserializeObject<System.Dynamic.ExpandoObject>(dataString);
string jsonOut = JsonConvert.SerializeObject(objIn, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
Ideally you wouldn't use dynamic, of course, but have proper types.
Having the logic handle differently named data from the logic itself seems a little backwards.
We plan to use this library in a project. Since we use JavaScript on the frontend side and C# on the backend side, we stumbled over a "problem" regarding the naming conventions in each of those languages. We use
camelCase
on the frontend side andPascalCase
on the backend side. Is there a way to use the same JSON Logic rules (all defined usingcamelCase
orPascalCase
) in on both sides, each using their own naming conventions in theirdata
objects (existing configuration or similar)?To illustrate it precisely with an example:
JSON Logic (using
camelCase
for thedata
properties)Data (using
PascalCase
for thedata
object)Should evaluate to
true
Our idea would be to provide a naming convention (
camelCase
,PascalCase
,snake_case
,kebab-case
) toJsonLogicEvaluator
and to use it to evaluate properties from thedata
object. Alternatively, when determining the values from thedata
object, in a simple case, one could simply make a case insensitive comparison of the names. Normally, this should not lead to collisions or the like, although it's possible.If there is no solution for this issue so far, am I willing to create a PR, if this feature is also needed by other users? Are there any contribution guidelines or something like this?