Pentaho JavaScript JSON - 基于键将json对象连接到现有的JSON文档中

时间:2021-12-08 21:15:46

Basically what i'm trying to do is to build up a Json document, with it's pieces all spread into smaller Json pieces, all rows containing the Keys needed to insert the smaller Json bits inside the correct json structure.

基本上我正在尝试做的是建立一个Json文档,它的所有部分都扩展成较小的Json部分,所有包含Keys的行都需要在正确的json结构中插入较小的Json位。

My problem starts in that i know next to nothing about JavaScript. So i would have to learn JavaScript from scratch(already doing), So i'll describe as best i can the issue and what i want to achieve.

我的问题开始于我对JavaScript几乎一无所知。所以我必须从头开始学习JavaScript(已经在做),所以我将尽可能地描述问题以及我想要实现的目标。

Issues: In every Pentaho / Json post i see a hardcoded(Like This answer, which is helpful but again, hardcoded number of fields) JavaScript to build a pre-formed Json structure, what i need is a way to to insert / create, dynamically built info into a Json Structure. And it also needs Nested Structures.

问题:在每个Pentaho / Json帖子中,我看到一个硬编码(像这个答案,这是有用的,但又是硬编码的字段数)JavaScript构建一个预先形成的Json结构,我需要的是一种插入/创建的方法,动态构建信息到Json结构中。它还需要嵌套结构。

So, in the start i would bulk build all the Flat Json structure, which can be easily done with the Json output Step, since it outputs built Json objects, the objects themselves can be built dynamically, and then just concatenated(Again i don't know if this is possible). After the flat part is done, comes the part of concatenating the other objects inside the correct structure, some are just more plain objects, others are Arrays of Objects(Nested part).

因此,在开始时我将批量构建所有Flat Json结构,这可以通过Json输出Step轻松完成,因为它输出构建的Json对象,对象本身可以动态构建,然后只是连接(再次,我不是)我知道这是否可行)。在完成平坦部分之后,将正确结构中的其他对象连接起来的部分,一些是更简单的对象,另一些是对象数组(嵌套部分)。

This is where i need confirmation from someone who understands this part that it is possible to achieve inside Pentaho JavaScript, or the only way using Pentaho is to build hardcoded structures. Below i'll show in Json examples what i want.

这是我需要确认此部分的人确认可以在Pentaho JavaScript中实现的地方,或者使用Pentaho的唯一方法是构建硬编码结构。下面我将在Json示例中展示我想要的内容。

This would be an example of the Flat JSON:

这将是Flat JSON的一个例子:

  {
        "Apolices": [{
                "Apolice": {
                    "APO_numero_apolice": "1321635113",
                    "APO_ramo": "312",
                    "APO_data_proposta": "22-05-2018",
                    "APO_valor_desconto": 0.0,
                    "APO_valor_liquido": 1550.39,
                    "APO_cod_parceiro_negocio": "1000",
                    "APO_inicio_vigencia": "22-05-2018",
                    "APO_status_apolice": "EMITIDA"
                }
            },
            {
                "Apolice": {
                    "APO_proposta": "3212121",
                    "APO_data_registro": "08-08-2018",
                    "APO_numero_apolice": "7891321498",
                    "APO_ramo": "515",
                    "APO_data_proposta": "22-03-2018",
                    "APO_valor_desconto": 0.0,
                    "APO_valor_liquido": 2150.72,
                    "APO_cod_parceiro_negocio": "7548151100",
                    "APO_inicio_vigencia": "22-07-2018",
                    "APO_status_apolice": "EMITIDA",
                    "APO_produto": null,
                    "APO_codigo_corretor": "812182",
                    "APO_fim_vigencia": "22-05-2019",
                    "APO_valor_bruto": 2320.8,
                    "APO_percentual_comissao": 19,
                    "APO_iof": null
                }
            }
        ]
    }

Then in the course of said implementation, the desired outcome would be something like :

然后在所述实施过程中,期望的结果将是:

  {
        "Apolices": [{
                "Apolice": {
                    "APO_numero_apolice": "1321635113",
                    "APO_ramo": "312",
                    "APO_data_proposta": "22-05-2018",
                    "APO_valor_desconto": 0.0,
                    "APO_valor_liquido": 1550.39,
                    "APO_cod_parceiro_negocio": "1000",
                    "APO_inicio_vigencia": "22-05-2018",
                    "APO_status_apolice": "EMITIDA"
                },
                "Item": {
                    "ITE_ano_fabricacao": "2001",
                    "ITE_modelo": "FOCUS SEDAN GHIA 2.0 MPI 16V 4P",
                    "ITE_ano_modelo": "2001",
                    "Cobertura": [{
                            "COB_cod_cobertura": "21",
                            "COB_valor_importancia": "50000",
                            "COB_valor_premio": "415,71",
                            "COB_cobertura": "RCF-V - Danos Materiais"
                        },
                        {
                            "COB_cod_cobertura": "17",
                            "COB_valor_importancia": "16712",
                            "COB_valor_premio": "1165,96",
                            "COB_cobertura": "Colisão,Incêndio e Roubo\/Furto"
                        }
                    ]
                }
            },
            {
                "Apolice": {
                    "APO_proposta": "3212121",
                    "APO_data_registro": "08-08-2018",
                    "APO_numero_apolice": "7891321498",
                    "APO_ramo": "515",
                    "APO_data_proposta": "22-03-2018",
                    "APO_valor_desconto": 0.0,
                    "APO_valor_liquido": 2150.72,
                    "APO_cod_parceiro_negocio": "7548151100",
                    "APO_inicio_vigencia": "22-07-2018",
                    "APO_status_apolice": "EMITIDA",
                    "APO_produto": null,
                    "APO_codigo_corretor": "812182",
                    "APO_fim_vigencia": "22-05-2019",
                    "APO_valor_bruto": 2320.8,
                    "APO_percentual_comissao": 19,
                    "APO_iof": null
                }
            }
        ]
    }

The Json Objects of "Item" and "Cobertura", and others, would come as already built Json objects, with the necessary keys to insert the entire object in the correct position of the structure.

“项目”和“的Cobertura”,和其他的JSON对象,会来为已建成的JSON对象,必要的钥匙插入整个对象结构的正确位置。

I have done next to no coding myself as of yet since i'm still learning JavaScript, but i already know that Pentaho's JavaScript is somewhat limited in resources, that's why i'm asking ahead if this is even possible inside Pentaho/Kettle

由于我还在学习JavaScript,但我已经知道Pentaho的JavaScript资源有限,这就是为什么我要提前询问Pentaho / Kettle中是否有可能

1 个解决方案

#1


0  

Don't be afraid of the resource limitations for Javascript in PDI. It uses the official Rhino OpenSource project which is 100% ES6 compatible.

不要害怕PDI中Javascript的资源限制。它使用与100%ES6兼容的官方Rhino OpenSource项目。

Of course, the dynamic nature of JS makes it a little bit slower, but I do not think the difference will be significant unless you have a continuous input flow of millions per minutes.

当然,JS的动态特性会让它变得有点慢,但我不认为除非你有每分钟数百万的连续输入流量,否则差异会很大。

#1


0  

Don't be afraid of the resource limitations for Javascript in PDI. It uses the official Rhino OpenSource project which is 100% ES6 compatible.

不要害怕PDI中Javascript的资源限制。它使用与100%ES6兼容的官方Rhino OpenSource项目。

Of course, the dynamic nature of JS makes it a little bit slower, but I do not think the difference will be significant unless you have a continuous input flow of millions per minutes.

当然,JS的动态特性会让它变得有点慢,但我不认为除非你有每分钟数百万的连续输入流量,否则差异会很大。