DocumentationWorkfront

Working with JSON exercise

Last update: Tue Dec 03 2024 00:00:00 GMT+0000 (Coordinated Universal Time)
  • Topics:
  • Workfront Fusion

CREATED FOR:

  • Beginner
  • User

Learn how to create and parse JSON within a scenario to support your design needs.

Exercise overview

The purpose of this exercise is to conceptually show how to utilize information sent into a scenario in a JSON format, parsing it into fields and items that you can map throughout your scenario. Then you can either grab information from those mapped arrays or aggregate the information into JSON to then be sent to another system that expects JSON as a receiving input.

Working with json Image 1

Steps to follow

Create a data structure and parsing JSON.

  1. Create a new scenario and name it “Working with JSON donut data.”

  2. For the trigger module, use the Set variable module.

  3. For the Variable name, type in “Donut data.”

  4. For the Variable value, copy and paste the contents of the “_Donut Data - Sample JSON.rtf” document found in the Fusion Exercise Files folder in your test drive.

    Working with json Image 2

  5. Rename this module “JSON from another connector.”

  6. Add a Parse JSON module.

  7. Click Add for the Data structure field.

  8. Select the Generator and paste the Donut Data - Sample JSON data that you copied into the Sample data field.

    Working with json Image 3

  9. Click Save, naming the data structure “Donut data.” Then click Save.

  10. Map the Donut data from the Set variable module to the JSON string field.

    Working with json Image 4

  11. Save your scenario, then click Run once to see the output.

    The output of the Parse JSON module should look like this:

    Working with json Image 5

    Map to specific array variables.

  12. Add a router after the Parse JSON module.

  13. In the top path, add a Set variable module.

  14. For the Variable name, type “Batter types by donut.”

  15. For the Variable value, use the map function to get the batter types from the batters array.

    Working with json Image 6

  16. Click OK, then Run once.

  17. Open the execution inspector to see the output bundle for each of the three operations, showing the batter types for each.

    Working with json Image 7

    Aggregate scenario data to JSON.

  18. On the lower routing path, add an Aggregate to JSON module.

  19. For the Source Module, choose the iterator–the Parse JSON module.

  20. For the Data structure, create or choose any data structure. For this example, use Donut data.

  21. Go ahead and map the fields over directly for this example, as shown below.

  22. When you get to batter and topping, notice these are arrays, so you need to click Add item to map them.

    Working with json Image 8

  23. Save the scenario and click Run once.

Look at the execution inspector for the Aggregate to JSON module and notice how you were able to aggregate three bundles into a single JSON string. You can then send this string to other systems that expect JSON.

Working with json Image 9

recommendation-more-help
c9fbcf61-6d19-481e-a9ab-f54a0ae0ee8a