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!

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...