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
Get Updates on the Splunk Community!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...