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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...