Service Virtualization

  • 1.  Is there an REST API available  to decode the json raw data into readable format ?

    Posted Jul 31, 2018 10:01 AM

    Hi All,

     

    Is there an REST API available  to decode the json raw data into readable format ?

    i want to use REST step available in DevTest and looking to decode the data in readable format.

     

    If there is anything else which is available in devtest and can be used please suggest. Thanks.



  • 2.  Re: Is there an REST API available  to decode the json raw data into readable format ?

    Broadcom Employee
    Posted Jul 31, 2018 11:31 PM

    Hi,

     

    Do you mean that the json raw data is some kinds of encoded binary data(like BASE64 encoded) which original format is JSON?
    Or do you want to change from JSON format to a different format(like csv, xml)?

     

    But both of them are not included in REST Invoke API(If the "REST API" in your comment means "REST Invoke API") for DevTest.
    But if you mean only using the REST Step in the test case, that is depends on the format of the response of the REST step.
    Sometimes you cannot use the REST step to get the suitable information from the response of REST Step like "REST STEP - download ZIP"

     

    Thank you,



  • 3.  Re: Is there an REST API available  to decode the json raw data into readable format ?

    Posted Aug 02, 2018 05:50 PM

    As Yusuke asked, is the "raw data" referring to specific value in the JSON payload that is base64 encoded? Or do you just want to display the JSON payload in a different more readable format?

     

    In the case you're talking about the first option then you can use a JSON Path Filter to extract the actual "raw data" value. You can then add another step (Execute Script) to decode the raw data into readable string:

     

    import org.apache.commons.codec.binary.Base64;

     

    String raw_data = testExec.getStateValue("rawDataProperty");
    byte[] encodedBytes = raw_data.getBytes();
    byte[] decodedBytes = Base64.decodeBase64(encodedBytes);
    String decodedReadableValue = new String(decodedBytes);

    testExec.setStateValue("decodedReadableValue", decodedReadableValue);

    return decodedReadableValue;

     

    If this is regarding the second option then I'm not aware of an out of the box feature that will transform the JSON payload to another format. A custom parser may have to be developed or perhaps make use of existing open source projects.



  • 4.  Re: Is there an REST API available  to decode the json raw data into readable format ?

    Posted Aug 11, 2018 09:46 AM

    I have tried the code suggested by you and that is not working out. I have filtered the rawdata value to a property and used in the code suggested by you but the response returned is not in readable format.

     

    to answer your question - i do not want to convert the json response to another format. i want to convert the part of json response which is in encrypted format to readable format



  • 5.  Re: Is there an REST API available  to decode the json raw data into readable format ?

    Posted Aug 11, 2018 09:10 AM

    Hi,  the requirement is to convert the particular response received from REST service to readable format. Here the response is in encoded format (eAHtW1lv4) and i want to convert this into readable format which will be in text format.

     

    The response which we are trying to decode is part of JSON response but not in JSON format individually. I was thinking to convert this either using a code or to send to an another API which can convert and return me a readable response. If you find anything do let me know. Thanks.



  • 6.  Re: Is there an REST API available  to decode the json raw data into readable format ?

    Posted Aug 11, 2018 05:16 PM

    I think what everyone is asking is what technique and Class was used to encrypt the data? Decoding without knowing the format is not going to help us advise on the solution.


    Are you certain the data (I.e., eAHtW1lv4) is in Base64 format? 



  • 7.  Re: Is there an REST API available  to decode the json raw data into readable format ?

    Posted Aug 14, 2018 06:00 AM

    I am not sure what techniques was used to encrypt data but looks like its base64. Please consider this is in base64 format and provide the solution. Thanks.



  • 8.  Re: Is there an REST API available  to decode the json raw data into readable format ?

    Posted Aug 14, 2018 07:33 AM

    Will_Truong provided a Base64 decoding sample in his post above. 

    The response indicates that the code did not work. Since the technique provided by Will is the standard approach for decoding Base64 data, we can only assume that the value is not Base64 encoded.

     

    We either need the full encoded data or more specifics about what did not work in the code snippet?

    Only upload the encoded data here if it does not contain private or customer data.



  • 9.  Re: Is there an REST API available  to decode the json raw data into readable format ?

    Posted Aug 14, 2018 01:45 PM

    You are using encryption/decryption and encoding/decoding interchangeably but they are two different things. Before we can continue assisting you with this, you should get clarification from your development team on whether the payload has been encrypted or encoded. In the case that it's the latter, encoded, then my snippet of code should handle it (the question here is, did you setup the JSON filter and my code up correctly? Can you share the test case so we can take a look? If you can't share the file in this open forum then open up a support ticket). In the case that it's the former, encrypted, you will need to find out what algorithm is used and gain access to the private key for decrypting the payload.