小编mf3*_*370的帖子

YAML 到 JSON Ruby

我有一个看起来像这样的 YAML 文件(带有机器人名称及其参数):

conf_file:

  pipeline_conf_path: /opt/etc/pipeline.conf
  runtime_conf_path: /opt/etc/runtime.conf


  asn_lookup:
    parameters:
      database: /opt/var/lib/bots/asn_lookup/ipasnteste.dat
    group: "Expert"
    name: "ASN Lookup"
    module: "one module"
    description: "modified by "

  modify:
    parameters:
      configuration_path: /opt/var/lib/bots/modify/modify.conf
    group: "Expert"
    name: "Modify"
    module: "one module"
    description: "modified"

 filter:
    parameters: 
      filter_action:
      filter_key:
      filter_regex:
      filter_value:

    group: "Expert"
    name: "Filter"
    module: "one module"
    description: "modified"
Run Code Online (Sandbox Code Playgroud)

我想将每个机器人转换为 JSON。例如,对于 asn-lookup,输出应该是这样的:

 "asn-lookup": {
        "parameters": {
            "database": "/opt/var/lib/bots/asn_lookup/ipasnteste.dat"
        },
        "group": "Expert",
        "name": "ASN Lookup",
        "module": "one module",
        "description": "modified by"
    }
Run Code Online (Sandbox Code Playgroud)

我已经有以下代码:

def generate_asn_bot
  config = YAML.load_file('my_conf.yaml') …
Run Code Online (Sandbox Code Playgroud)

ruby json yaml

4
推荐指数
2
解决办法
4193
查看次数

Ruby Hash的JSON文件

我有一个由机器人名称及其参数和配置组成的JSON文件,它看起来像这样:

{
    "csv-collector": {
        "parameters": {
            "delete_file": false,
            "feed": "FileCollector",
            "provider": "ola",
            "path": "/tmp/",
            "postfix": ".csv",
            "rate_limit": 300
        },
        "group": "Collector",
        "name": "Fileinput",
        "module": "abc",
        "description": "Fileinput collector fetches data from a file."
    },
    "csv-parser": {
        "parameters": {
            "columns": "classification.type,destination.ip",
            "default_url_protocol": "http://",
            "delimiter": ",",
            "skip_header": true,
            "type": "c&c"
        },
        "group": "Parser",
        "name": "Generic CSV",
        "module": "efg",
        "description": "Generic CSV Parser is a generic bot"
    }
}
Run Code Online (Sandbox Code Playgroud)

我想将它解析为Ruby Hash,其中机器人名称为"csv-collector","csv-parser"为键,其余内容为值.像这样的东西:

my_hash = {"csv-collector" => {"parameters": {
                "delete_file": false,
                "feed": "FileCollector",
                "provider": "ola", …
Run Code Online (Sandbox Code Playgroud)

ruby json file

1
推荐指数
1
解决办法
579
查看次数

标签 统计

json ×2

ruby ×2

file ×1

yaml ×1