DevOps Pre-Requisite Course - Json Path Lab Session difficulty

hi, I just started with DevOps Pre-Requisite Course, Json Path Lab. I don’t seem to understand the task in this lab practice. Can someone please help? Thank you.

Which task do you not understand?

I don’t seem to understand the requirement of the lab session. I can’t get to solve the tasks.

First you must understand what is JSON and how it is represented. This should be covered by the videos up to this point. JSONPath is about getting selected segments out of a whole load of JSON (could be megabytes of it).

Ok, let’s look at question 2

Develop a JSON PATH query to extract the kind of object. A file named q2.json is provided in the terminal. Your task is to develop a JSON path query to extract the expected output from the Source Data.

Expected output should be like this

    [
      {
        "color": "white",
        "price": "$120,000"
      }
    ]
  1. Look at the source data

    cat q2.json
    

    output

    {
        "car": {
            "color": "blue",
            "price": "$20,000"
        },
        "bus": {
            "color": "white",
            "price": "$120,000"
        }
    }
    
  2. Notice from the above, the part of all of that file we need, which is the properties of bus, so this will yield that result

    cat q2.json | jpath $.bus
    

    output

    [
      {
        "color": "white",
        "price": "$120,000"
      }
    ]
    

    which is what is requested.

  3. Create the answer file as requested

    vi /root/answer2.sh
    

    Enter the command into the editor
    cat q2.json | jpath $.bus
    Save the file

If you wanted the price of the bus, it would be
cat q2.json | jpath $.bus.price
or the color of the car
cat q2.json | jpath $.car.color
or all the car’s details (instead of the bus)
cat q2.json | jpath $.car

If you get stuck with vi editor, read this.

1 Like

Thank you so much @Alistair_KodeKloud. This was very helpful.