All Apps and Add-ons

Handler Arguments from responsehandlers.py for REST API Modular Input app adding raw data

pranayadla
New Member

I would like to ask how could I transform Json data from one format to another Json format.

class APMRESTeventHandler:

def __init__(self,**args):
    pass

def __call__(self, response_object,raw_response_output,response_type,req_args,endpoint):
    if response_type == "json":
        output = json.loads(raw_response_output)
        data1=output['columnHeader']
        data2=output['formattedData']
        for i in data2:
            dic=dict(zip(data1,i))
            print_xml_stream(json.dump(dic,ensure_ascii=False))
    else:
        print_xml_stream(raw_response_output)
Tags (1)
0 Karma

Damien_Dallimor
Ultra Champion

Using a custom response handler is the correct approach.

Can you please ask the question with more context.

Such as,

1) what actual problem are you encountering with your handler above ?
2) any log errors pertaining to 1
3) what does your configuration look like pertaining to 1
4) to help troubleshooot , what do the target and destination JSON format look like ?

0 Karma

pranayadla
New Member

We are trying to use custom response handler to transform data from on JSON format to Another JSON format.

In RAW data we are getting columnHeader and formattedData but target JSON needs to be combination of these two.

We have used given handler to transform it's working fine in locally if we took JSON file as input. But not working when we used this in custom response handler. Data coming in as it is not transformed to another JSON format.

0 Karma

Damien_Dallimor
Ultra Champion

And anything to add for points 2,3,4 ?

0 Karma

pranayadla
New Member

Thanks for your help this is resolved we have changed code to this

ef init(self,**args):
pass
def call(self, response_object,raw_response_output,response_type,req_args,endpoint):
if response_type == "json":
output = json.loads(raw_response_output)
data1=output['columnHeader']
data2=output['formattedData']
for i in data2:
dic=dict(zip(data1,i))
print_xml_stream(json.dumps(dic))
else:
print_xml_stream(raw_response_output)

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...