• DOCUMENTATION
  • WORKATO BLOG
  • PRODUCT BLOG
  • Return to Workato
  • Log in
  • ☰
  • Solutions Articles
  • Forums/Discussions
  • Submitted Tickets
New Topic
Discussions Recipe Building Recipe Building Questions
S

Saul Macht

started a topic about 2 years ago
Answered

How do I sort a JSON object according to a specific key?

I would like to sort alphabetically according to a key.


Best Answer
B
Brandon Chew from Workato said about 2 years ago

A JSON object can be sorted with Workato using 2 types of actions


  1. Ruby


After obtaining the JSON object, use the Ruby action and sort the unsorted object by entering the following code:


  • Ascending


unsorted.sort_by { |hash| hash['key_to_order_by'] }


  • Descending


unsorted.sort_by { |hash| hash['key_to_order_by'] }.reverse

 

An example recipe can be found HERE.

 

       2. Collections [Business Plus & Above]

 

After obtaining the JSON object, use the Collections by Workato action to 


  • Create a list in Collection [Using the JSON object as the input]
  • Query list in Collection [To sort the JSON object]


An example recipe can be found HERE.

Answer
B

Brandon Chew from Workato

said about 2 years ago

A JSON object can be sorted with Workato using 2 types of actions


  1. Ruby


After obtaining the JSON object, use the Ruby action and sort the unsorted object by entering the following code:


  • Ascending


unsorted.sort_by { |hash| hash['key_to_order_by'] }


  • Descending


unsorted.sort_by { |hash| hash['key_to_order_by'] }.reverse

 

An example recipe can be found HERE.

 

       2. Collections [Business Plus & Above]

 

After obtaining the JSON object, use the Collections by Workato action to 


  • Create a list in Collection [Using the JSON object as the input]
  • Query list in Collection [To sort the JSON object]


An example recipe can be found HERE.

Login to post a comment

Still can't find your solution?

Send us a ticket, we will try our best to assist you with your problem

Documentation
Developer's Library
Tutorials
eBooks
Product Hour
Product Blog
Workato Blog
Product updates
Customer Stories
© Workato 2020   Privacy   Terms   +1 (844) 469-6752
  • Documentation
  • Workato Blog
  • Product Blog
  • Solutions
  • Forums
  • Tickets
  • Log in
  • Return to Workato