bazaarvoice / jolt

JSON to JSON transformation library written in Java.
Apache License 2.0
1.54k stars 328 forks source link

how to read required attributes from a config file #1265

Closed naveenpi closed 1 month ago

naveenpi commented 2 months ago

I have an input like:

{

"attribute_set":[ { "attribute": "ABC", "value": 1 }, { "attribute": "KFC", "value": 1 }, { "attribute": "OLW", "value": 1 }, { "attribute": "PRIOF", "value": 1 } .. 600 more attributes like above ] }

output i need something like this: The main ask here is i want to maintain the required attributes in config.json file. My jolt should get the required attributes from the file and should give the output. is there a way to embed custom functions in jolt mapping (preferably java)?

{

"attributes":{ "ABC": 1, "KFC": 1 } }

Example jolt i have now:

{ "attribute_set:" { "*": { "attribute": "ABC|KFC":{ - // i want this list to come from a config file "@(2,value)": "attributes.&1" } } } }

LucaBiscotti commented 2 months ago

Hi @naveenpi quick question to better understand the problem: Where do you put the required attributes you say you need(like ABC and KFC in your example)? Are they in the same json file of the input? Are they in the attributes of the file(if you are using nifi)? Or are they manually chosen? Without this info it's hard to understand how to proceed. Meanwhile I can suggest you this jolt:

[
  {
    "operation": "shift",
    "spec": {
      "attribute_set": {
        "*": {
          "@(0,value)": "attributes.@(0,attribute)"
        }
      }
    }
  }
]

What it does is basically to get every attribute and mapping it with its associated value. If you can let me know how do you intend to pass the required attributes to the process, we can then find the complete solution to this problem

thinkcloudmasters commented 1 month ago

[ { "operation": "default", "spec": { "attributes": "value" } }, { "operation": "shift", "spec": { "attributes": "attributes" } }, { "operation": "modify-overwrite-beta", "spec": { "attributes": "=concat(@(1,attributes), '')" } } ]

you can also try this jolt AI spec generation site https://powerjolt.azurewebsites.net

naveenpi commented 1 month ago

thank you @LucaBiscotti , @thinkcloudmasters