DataPower

DataPower

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

sorting json arrary in Gateway script

  • 1.  sorting json arrary in Gateway script

    Posted 03/27/20 09:34 AM
    do we have any function to sort json array in alphabetical order in gateway script ?.

    i am aware it is available in latest version (2018.4.1.8)

    ------------------------------
    santhosh
    ------------------------------


  • 2.  RE: sorting json arrary in Gateway script

    Posted 03/27/20 10:04 AM
    Hi,
    what version are you referring into if not the newest 2018.4.1.8?

    --Hermanni

    ------------------------------
    Hermanni Pernaa
    ------------------------------



  • 3.  RE: sorting json arrary in Gateway script

    Posted 03/27/20 11:50 PM
    I am using Firmware 2018.4.1.6

    ------------------------------
    santhosh
    ------------------------------



  • 4.  RE: sorting json arrary in Gateway script

    Posted 03/30/20 04:30 AM
    Ok. Did you verify that the functions don't work?
    I'm running 2018.4.1.6 firmware in a Docker container and at least for me 
    both sort() and reverse() seem to work for array of strings and array of numbers. 

    --Hermanni


    ------------------------------
    Hermanni Pernaa
    ------------------------------



  • 5.  RE: sorting json arrary in Gateway script

    Posted 03/30/20 05:17 AM

    Yes, works, here is simple sample:

    const months = ['March', 'Jan', 'Feb', 'Dec'];
    months.sort();
    session.output.write(months);



    ------------------------------
    Hermann Stamm-Wilbrandt
    Compiler Level 3 support & Fixpack team lead
    IBM DataPower Gateways (⬚ᵈᵃᵗᵃ / ⣏⠆⡮⡆⢹⠁⡮⡆⡯⠂⢎⠆⡧⡇⣟⡃⡿⡃)
    ------------------------------



  • 6.  RE: sorting json arrary in Gateway script

    Posted 03/30/20 09:42 AM

    GatewayScript in DataPower is essentially JavaScript with additional modules provided to allow access to DataPower metadata and functionality.  The Array.sort function is a basic JavaScript capability.

    Best Regards,

    Steve




  • 7.  RE: sorting json arrary in Gateway script

    Posted 03/31/20 09:44 AM
    Edited by santhosh yelimineti 03/31/20 09:46 AM
    Thanks for the replies

    I am looking for similar to this https://github.com/ShivrajRath/jsonabc

    ------------------------------
    santhosh
    ------------------------------



  • 8.  RE: sorting json arrary in Gateway script

    Posted 03/31/20 10:10 AM

    Have you tried to use the code in index.js? It should work.

    Rename to jsonabc.js and upload to DataPower local: folder.
    Then upload src/app.js to local: folder as well, and use that in GatewayScript action.



    ------------------------------
    Hermann Stamm-Wilbrandt
    Compiler Level 3 support & Fixpack team lead
    IBM DataPower Gateways (⬚ᵈᵃᵗᵃ / ⣏⠆⡮⡆⢹⠁⡮⡆⡯⠂⢎⠆⡧⡇⣟⡃⡿⡃)
    ------------------------------



  • 9.  RE: sorting json arrary in Gateway script

    Posted 03/31/20 10:52 AM
    Thanks a lot Hermann

    It worked perfectly . So practically we can use all nodejs scripts in datapower? or do we have any limitations.

    ------------------------------
    santhosh
    ------------------------------



  • 10.  RE: sorting json arrary in Gateway script

    Posted 03/31/20 11:40 AM

    Not all, but many, find the details of GatewayScript programming model here:

    https://www.ibm.com/support/knowledgecenter/SS9H2Y_7.7.0/com.ibm.dp.doc/gatewayscript_model.html

    "... Gateway script includes ECMAScript, CommonJS, and DataPower-specific GatewayScript APIs ..."



    ------------------------------
    Hermann Stamm-Wilbrandt
    Compiler Level 3 support & Fixpack team lead
    IBM DataPower Gateways (⬚ᵈᵃᵗᵃ / ⣏⠆⡮⡆⢹⠁⡮⡆⡯⠂⢎⠆⡧⡇⣟⡃⡿⡃)
    ------------------------------