Challenge: Convert an Object to JSON File

Can we serialize data by converting an object into a JSON file?

Problem statement

Convert the given object into a JSON file and write that JSON file into the standard output using the cat command.

Given data

An object given below:

$age = @{
    david = 34
    prateek= 35
    singh= 18

Expected output

A JSON file containing the data of the age object.

Coding exercise

This problem is designed to check your understanding, so you are encouraged to solve it on your own. If you get completely stuck, refer to the next lesson which will explain the solution in detail.


Hint: For convenience, use the directory /usercode/jfile.json to store our JSON file.

Note: Run the cat jfile.json command after hitting the “Run” button to see the output.

Get hands-on with 1200+ tech skills courses.