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!

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...