简体   繁体   English

用于动态转换 JSON 的规则引擎或模板语言

[英]RuleEngine or Templating language to transform JSON dynamically

I have a json that needs to be transformed dynamically into another json.我有一个 json 需要动态转换为另一个 json。 I want to map a property from input json to the property of target json, while mapping i also want to apply rule.我想 map 从输入 json 到目标 json 的属性的属性,同时映射我也想应用规则。 Below is sample pseudo code下面是示例伪代码

if (input.State == "TX")
   output.TaxRate = 12.00
 else
   output.TaxRate = input.Rate..

These rules and target json structure keeps changing very often.这些规则和目标 json 结构经常变化。 So I was looking for templating language or rule engine where i can dynamically apply rules or map to different target json.所以我一直在寻找模板语言或规则引擎,我可以在其中动态地将规则或 map 应用到不同的目标 json。

I looked into Microsoft Rules Engine that use JSON based Template.我查看了使用基于 JSON 模板的Microsoft 规则引擎 But as most of the other open source rule engine it does not execute actions/methods when condition is true.但与大多数其他开源规则引擎一样,当条件为真时,它不会执行操作/方法。 It only evaluates the linq expression and returns boolean.它只计算 linq 表达式并返回 boolean。 Has anyone try to extend this rule engine to execute action/method dynamically?有没有人尝试扩展这个规则引擎来动态执行动作/方法?

I am open for any other suggestions, guidelines.我愿意接受任何其他建议和指导。 I prefer templating language so i can provide UI to edit template dynamically.我更喜欢模板语言,所以我可以提供 UI 来动态编辑模板。

As of v3, RulesEngine provides support for actions - https://github.com/microsoft/RulesEngine/wiki/Actions从 v3 开始,RulesEngine 提供对操作的支持 - https://github.com/microsoft/RulesEngine/wiki/Actions

It supports OutputExpression which can do trasformation using expression.它支持OutputExpression,可以使用表达式进行转换。 If you need more complex transformation, you can even create your own action and plug it in RulesEngine如果您需要更复杂的转换,您甚至可以创建自己的操作并将其插入 RulesEngine

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM