Representing logic as data in JSON

前端 未结 12 1727
眼角桃花
眼角桃花 2021-01-29 21:37

For business reasons we need to externalize some conditional logic into external files: preferably JSON.

A simple filter-by scenario could be handled by adding a node a

12条回答
  •  难免孤独
    2021-01-29 22:02

    Logic can be implemented with "logicOp": "Operator" on a "set": ["a","b" ...] For cHau's example:

    "var": {
             "logicOp": "And",
             "set": ["value1",
                     {
                        "LogicOp": "Or",
                        "set": ["value2", "value3"]
                     }
                  ]
           }
    

    There can also be other attributes/operations for the set for example

    "val": { "operators": ["min": 0, "max": 2], "set": ["a", "b", "c"] } 
    

    For a sunday with two scoops of one or more icecream types, 1 toppings and whipcream

    "sunday": {
                "icecream": { 
                              "operators": [ "num": 2,
                                            "multipleOfSingleItem": "true"],
                              "set": ["chocolate", "strawberry", "vanilla"]
                            },
                "topping": {
                              "operators": ["num": 1],
                              "set": ["fudge", "caramel"]
                           },
                "whipcream": "true"
              }
    

提交回复
热议问题