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.
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.
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.
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).
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.
This would be an example of the 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.
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