diff --git a/Module 5/Question 1/Problem1.json b/Module 5/Question 1/Problem1.json new file mode 100644 index 00000000..7293ecc3 --- /dev/null +++ b/Module 5/Question 1/Problem1.json @@ -0,0 +1,184 @@ +Input Json: { + "orders": [ + { + "orderId": 1, + "orderDate": "2022-02-20T12:34:56Z", + "customer": { + "customerId": 1, + "firstName": "John", + "lastName": "Doe", + "email": "johndoe@example.com", + "address": { + "street": "123 Main St", + "city": "Anytown", + "state": "CA", + "zip": "12345" + } + }, + "items": [ + { + "itemId": 1, + "name": "Product A", + "quantity": 2, + "price": 10 + }, + { + "itemId": 2, + "name": "Product B", + "quantity": 1, + "price": 20 + } + ] + }, + { + "orderId": 2, + "orderDate": "2022-02-21T09:12:34Z", + "customer": { + "customerId": 2, + "firstName": "Jane", + "lastName": "Smith", + "email": "janesmith@example.com", + "address": { + "street": "456 Oak St", + "city": "Somewhere", + "state": "NY", + "zip": "67890" + } + }, + "items": [ + { + "itemId": 3, + "name": "Product C", + "quantity": 3, + "price": 15 + } + ] + } + ] +} + + + +Json Spec: [ + { + "operation": "modify-overwrite-beta", + "spec": { + "orders": { + "*": { + "customer": { + "address": "=concat(@(1,address.street),' ',@(1,address.city), ' ', @(1,address.state), ' ',@(1,address.zip))" + }, + "itemTemp": "@(1,items)" + } + } + } + }, + { + "operation": "modify-overwrite-beta", + "spec": { + "orders": { + "*": { + "itemTemp": { + "*": { + "inverseValue": "=divide(1,@(1,price))", + "temp": "=divideAndRound(2, @(1,quantity), @(1,inverseValue))", + "price": "=toDouble(@(1,price))" + } + } + } + } + } + }, + { + "operation": "shift", + "spec": { + "orders": { + "*": { + "*": "orders[&1].&", + "itemTemp": { + "*": { + "temp": "orders[#4].total" + } + } + } + } + } + }, + { + "operation": "modify-overwrite-beta", + "spec": { + "orders": { + "*": { + "total": "=doubleSum(@(1,total))" + } + } + } + }, + { + "operation": "remove", + "spec": { + "orders": { + "*": { + "items": { + "*": { + "inverseValue": "", + "temp": "" + } + } + } + } + } + } +] + + +Output Json: { + "orders": [ + { + "orderId": 1, + "orderDate": "2022-02-20T12:34:56Z", + "customer": { + "customerId": 1, + "firstName": "John", + "lastName": "Doe", + "email": "johndoe@example.com", + "address": "123 Main St Anytown CA 12345" + }, + "items": [ + { + "itemId": 1, + "name": "Product A", + "quantity": 2, + "price": 10.0 + }, + { + "itemId": 2, + "name": "Product B", + "quantity": 1, + "price": 20.0 + } + ], + "total": 40.0 + }, + { + "orderId": 2, + "orderDate": "2022-02-21T09:12:34Z", + "customer": { + "customerId": 2, + "firstName": "Jane", + "lastName": "Smith", + "email": "janesmith@example.com", + "address": "456 Oak St Somewhere NY 67890" + }, + "items": [ + { + "itemId": 3, + "name": "Product C", + "quantity": 3, + "price": 15.0 + } + ], + "total": 45.0 + } + ] +} \ No newline at end of file diff --git a/Module 5/Question 1/approach.md b/Module 5/Question 1/approach.md new file mode 100644 index 00000000..fc9831e9 --- /dev/null +++ b/Module 5/Question 1/approach.md @@ -0,0 +1,16 @@ +## Number of Oprations 3 +1. modify-overwrite-beta (3 times) +2. shift (1 times) +3. remove (1 times) + +## Explanation + +* In the first operation **(modify-oveerwrite-beta)** all the address get concat (joined separated by space) and a new tempItem is created in which i have stored items tempararly. + +* In the second operation **(modify-oveerwrite-beta)** i have calculated the inverseValue and the divide that value with quantity. For getting the product of price and quantity. + +* In the third operation **(shift)** I have created a list of total value of all items purchased by a customer for calculating the total price. + +* In fourth opration **(modify-overwrite-beta)** calculated the total price using **doubleSum** function. + +* At the last I have used **remove** operation to delete the unwanted fields from the json / final output.. \ No newline at end of file diff --git a/Module 5/Question 10/Problem10.json b/Module 5/Question 10/Problem10.json new file mode 100644 index 00000000..b81e5665 --- /dev/null +++ b/Module 5/Question 10/Problem10.json @@ -0,0 +1,68 @@ +Input Json + +{ + "name": "John Smith", + "age": 35, + "address": { + "street": "123 Main St", + "city": "Anytown", + "state": "CA", + "zip": "12345" + }, + "phone_numbers": [ + { + "type": "home", + "number": "555-1234" + }, + { + "type": "work", + "number": "555-5678" + } + ] +} + +Json Spec + +[ + { + "operation": "modify-default-beta", + "spec": { + "nameList": "=split(' ', @(1,name))", + "firstName": "=firstElement(@(1,nameList))", + "lastName": "=lastElement(@(1,nameList))", + "phone_number_count": "=size(@(1,phone_numbers))" + } + }, + { + "operation": "remove", + "spec": { + "name": "", + "nameList": "" + } + } +] + +Output Json + +{ + "age": 35, + "address": { + "street": "123 Main St", + "city": "Anytown", + "state": "CA", + "zip": "12345" + }, + "phone_numbers": [ + { + "type": "home", + "number": "555-1234" + }, + { + "type": "work", + "number": "555-5678" + } + ], + "firstName": "John", + "lastName": "Smith", + "phone_number_count": 2 +} \ No newline at end of file diff --git a/Module 5/Question 10/approach.md b/Module 5/Question 10/approach.md new file mode 100644 index 00000000..31939fad --- /dev/null +++ b/Module 5/Question 10/approach.md @@ -0,0 +1,9 @@ +## Number of Operation 2 +1. "modify-default-beta (1 times) +2. remove (1 times) + +## Explanation: + +* First operation **(modify-default-beta)** is used split the name and then assign then separately in fname and lname keys. Ath last I have used size function to count the number of object present inside the phone_numbers. + +* At last **(remove)** operation is used remove the name and temp key nameList. \ No newline at end of file diff --git a/Module 5/Question 11/Problem11.json b/Module 5/Question 11/Problem11.json new file mode 100644 index 00000000..aeb3162e --- /dev/null +++ b/Module 5/Question 11/Problem11.json @@ -0,0 +1,45 @@ +Input Json + +{ + "items": [ + { + "name": "item1", + "value": 10 + }, + { + "name": "item2", + "value": 20 + } + ] +} + +Json Spec + +[ + { + "operation": "shift", + "spec": { + "items": { + "*": { + "name": "items[#2].itemName", + "value": "items[#2].itemValue" + } + } + } + } +] + + +Output Json +{ + "items": [ + { + "itemName": "item1", + "itemValue": 10 + }, + { + "itemName": "item2", + "itemValue": 20 + } + ] +} \ No newline at end of file diff --git a/Module 5/Question 11/approach.md b/Module 5/Question 11/approach.md new file mode 100644 index 00000000..73a61382 --- /dev/null +++ b/Module 5/Question 11/approach.md @@ -0,0 +1,6 @@ +## Number of operations 1 +1. shift (1 times) + +## Explanation: + +* In first operation **(shift)** i have rename the keys from name to itemName and from value to itemValue. \ No newline at end of file diff --git a/Module 5/Question 12/Problem12.json b/Module 5/Question 12/Problem12.json new file mode 100644 index 00000000..2bbc3c53 --- /dev/null +++ b/Module 5/Question 12/Problem12.json @@ -0,0 +1,62 @@ +Input Json + +{ + "employee": { + "firstName": "John", + "lastName": "Doe", + "address": { + "street": "123 Main St", + "city": "Anytown", + "state": "CA", + "zip": "12345" + }, + "phones": [ + { + "type": "home", + "number": "555-555-1234" + }, + { + "type": "work", + "number": "555-555-5678" + } + ] + } +} + +Json Spec + +[ + { + "operation": "modify-overwrite-beta", + "spec": { + "employee": { + "name": "=concat(@(1,firstName),' ',@(1,lastName))", + "address": "=concat(@(1,address.street),' ',@(1,address.city),' ',@(1,address.state),' ',@(1,address.zip))" + } + } + }, + { + "operation": "shift", + "spec": { + "employee": { + "name": "&", + "address": "&", + "phones": "phoneNumbers" + } + } + } +] + +Output Json + +{ + "name" : "John Doe", + "address" : "123 Main St Anytown CA 12345", + "phoneNumbers" : [ { + "type" : "home", + "number" : "555-555-1234" + }, { + "type" : "work", + "number" : "555-555-5678" + } ] + } \ No newline at end of file diff --git a/Module 5/Question 12/approach.md b/Module 5/Question 12/approach.md new file mode 100644 index 00000000..af75a3cc --- /dev/null +++ b/Module 5/Question 12/approach.md @@ -0,0 +1,9 @@ +## Number of operation 2 +1. modify-overwrite-beta (1 times) +2. shift (1 times) + +## Explanation: + +* In first operation **(modify-overwrite-beta)** i have concat firstName and lastName and store the values in a key `name` and then concatinate the address (street,city,state,zip) and overwrite the address key. + +* At last i have user **shift** operation to structure the input as per our desired output. \ No newline at end of file diff --git a/Module 5/Question 13/Problem13.json b/Module 5/Question 13/Problem13.json new file mode 100644 index 00000000..2ff6dfe3 --- /dev/null +++ b/Module 5/Question 13/Problem13.json @@ -0,0 +1,64 @@ +Input Json +{ + "employees": [ + { + "id": "001", + "name": "John", + "department": "HR" + }, + { + "id": "002", + "name": "Jane", + "department": "Sales" + }, + { + "id": "003", + "name": "Bob", + "department": "IT" + } + ] +} + +Json spec + +[ + { + "operation": "shift", + "spec": { + "employees": { + "*": { + "@": "employees.@(1,id)" + } + } + } + }, + { + "operation": "remove", + "spec": { + "employees": { + "*": { + "id": "" + } + } + } + } +] + +Output Json + +{ + "employees": { + "001": { + "name": "John", + "department": "HR" + }, + "002": { + "name": "Jane", + "department": "Sales" + }, + "003": { + "name": "Bob", + "department": "IT" + } + } +} \ No newline at end of file diff --git a/Module 5/Question 13/approach.md b/Module 5/Question 13/approach.md new file mode 100644 index 00000000..020058dd --- /dev/null +++ b/Module 5/Question 13/approach.md @@ -0,0 +1,9 @@ +## Number of operation 2 +1. shift (1 times) +2. remove (1 times) + +## Explanation: + +* In first operation **(shift)** i have assign a key to all objects of employees list. The key is nothing but the id of that object. + +* In the second operation **(remove)** i have removed the unwanted field `id` of every object. diff --git a/Module 5/Question 14/Problem14.json b/Module 5/Question 14/Problem14.json new file mode 100644 index 00000000..02e5415a --- /dev/null +++ b/Module 5/Question 14/Problem14.json @@ -0,0 +1,93 @@ +Input Json + +{ + "employees": [ + { + "id": "001", + "name": "John", + "department": "HR", + "phone": [ + { + "type": "home", + "number": "555-555-1234" + }, + { + "type": "work", + "number": "555-555-5678" + } + ] + }, + { + "id": "002", + "name": "Jane", + "department": "Sales", + "phone": [ + { + "type": "home", + "number": "555-555-4567" + }, + { + "type": "work", + "number": "555-555-8901" + } + ] + } + ] +} + +Json Spec + + +[ + { + "operation": "shift", + "spec": { + "employees": { + "*": { + "id": "employees.[#2].&", + "name": "employees.[#2].&", + "department": "employees.[#2].&", + "phone": { + "*": { + "@number": "employees.[#4].@type" + } + } + } + } + } + }, + { + "operation": "shift", + "spec": { + "employees": { + "*": { + "*": "employees.[#2].&", + "home": "employees.[#2].homePhone", + "work": "employees.[#2].workPhone" + } + } + } + } +] + + +Ouput Json + +{ + "employees": [ + { + "id": "001", + "name": "John", + "department": "HR", + "homePhone": "555-555-1234", + "workPhone": "555-555-5678" + }, + { + "id": "002", + "name": "Jane", + "department": "Sales", + "homePhone": "555-555-4567", + "workPhone": "555-555-8901" + } + ] +} \ No newline at end of file diff --git a/Module 5/Question 14/approach.md b/Module 5/Question 14/approach.md new file mode 100644 index 00000000..6ac52a3a --- /dev/null +++ b/Module 5/Question 14/approach.md @@ -0,0 +1,7 @@ +## Number of operation 1 +1. shift (2 times) + +## Explanation: + +* In first operation **(shift)** i have flaten all the objects of employees. +* Then I have used **(shift)** operation to rename the home as homePhone and work as workPhone. \ No newline at end of file diff --git a/Module 5/Question 15/Problem15.json b/Module 5/Question 15/Problem15.json new file mode 100644 index 00000000..38291bf9 --- /dev/null +++ b/Module 5/Question 15/Problem15.json @@ -0,0 +1,188 @@ +Input Json + +{ + "orders": [ + { + "id": "order1", + "date": "2022-01-01T00:00:00Z", + "customerId": "customer1", + "items": [ + { + "id": "item1", + "name": "Product 1", + "price": 10, + "quantity": 2 + }, + { + "id": "item2", + "name": "Product 2", + "price": 20, + "quantity": 1 + } + ], + "totalPrice": 40 + }, + { + "id": "order2", + "date": "2022-02-01T00:00:00Z", + "customerId": "customer1", + "items": [ + { + "id": "item3", + "name": "Product 3", + "price": 30, + "quantity": 3 + } + ], + "totalPrice": 90 + }, + { + "id": "order3", + "date": "2022-03-01T00:00:00Z", + "customerId": "customer2", + "items": [ + { + "id": "item4", + "name": "Product 4", + "price": 40, + "quantity": 4 + } + ], + "totalPrice": 160 + } + ] +} + +Json Spec + +[ + { + "operation": "shift", + "spec": { + "orders": { + "*": { + "@": "@(1,customerId).orders[]" + } + } + } + }, + { + "operation": "shift", + "spec": { + "*": "customers" + } + }, + { + "operation": "shift", + "spec": { + "customers": { + "*": { + "orders": { + "*": { + "*": "customers[#4].orders[#2].&", + "@totalPrice": "customers[#4].totalAmount" + } + } + } + } + } + }, + { + "operation": "modify-overwrite-beta", + "spec": { + "customers": { + "*": { + "totalAmount": "=intSum(@(1,totalAmount))", + "id": "@(1,orders[0].customerId)" + }, + "[0]": { + "name": "John Doe" + }, + "[1]": { + "name": "Jane Doe" + } + } + } + }, + { + "operation": "remove", + "spec": { + "customers": { + "*": { + "orders": { + "*": { + "customerId": "" + } + } + } + } + } + } +] + + +Output Json + +{ + "customers": [ + { + "totalAmount": 130, + "orders": [ + { + "id": "order1", + "date": "2022-01-01T00:00:00Z", + "items": [ + { + "id": "item1", + "name": "Product 1", + "price": 10, + "quantity": 2 + }, + { + "id": "item2", + "name": "Product 2", + "price": 20, + "quantity": 1 + } + ], + "totalPrice": 40 + }, + { + "id": "order2", + "date": "2022-02-01T00:00:00Z", + "items": [ + { + "id": "item3", + "name": "Product 3", + "price": 30, + "quantity": 3 + } + ], + "totalPrice": 90 + } + ], + "name": "John Doe", + "id": "customer1" + }, + { + "totalAmount": 160, + "orders": [ + { + "id": "order3", + "date": "2022-03-01T00:00:00Z", + "items": [ + { + "id": "item4", + "name": "Product 4", + "price": 40, + "quantity": 4 + } + ], + "totalPrice": 160 + } + ], + "name": "Jane Doe", + "id": "customer2" + } + ] +} \ No newline at end of file diff --git a/Module 5/Question 15/Problem15_b.json b/Module 5/Question 15/Problem15_b.json new file mode 100644 index 00000000..3789c587 --- /dev/null +++ b/Module 5/Question 15/Problem15_b.json @@ -0,0 +1,183 @@ +Input Json + +{ + "orders": [ + { + "id": "order1", + "date": "2022-01-01T00:00:00Z", + "customerId": "customer1", + "items": [ + { + "id": "item1", + "name": "Product 1", + "price": 10, + "quantity": 2 + }, + { + "id": "item2", + "name": "Product 2", + "price": 20, + "quantity": 1 + } + ], + "totalPrice": 40 + }, + { + "id": "order2", + "date": "2022-02-01T00:00:00Z", + "customerId": "customer1", + "items": [ + { + "id": "item3", + "name": "Product 3", + "price": 30, + "quantity": 3 + } + ], + "totalPrice": 90 + }, + { + "id": "order3", + "date": "2022-03-01T00:00:00Z", + "customerId": "customer2", + "items": [ + { + "id": "item4", + "name": "Product 4", + "price": 40, + "quantity": 4 + } + ], + "totalPrice": 160 + } + ] +} + + +Json Spec + +[ + { + "operation": "shift", + "spec": { + "orders": { + "*": { + "@": "@(1,customerId)[]" + } + } + } + }, + { + "operation": "modify-overwrite-beta", + "spec": { + "customer1": { + "*": { + "name": "John Smith", + "amount": "@(1,totalPrice)" + } + }, + "customer2": { + "*": { + "name": "Jane Doe", + "amount": "@(1,totalPrice)" + } + } + } + }, + { + "operation": "shift", + "spec": { + "*": { + "*": { + "customerId": "customers[#3].id", + "name": "customers[#3].name", + "id": "customers[#3].orders[&1].&", + "date": "customers[#3].orders[&1].&", + "items": "customers[#3].orders[&1].&", + "totalPrice": "customers[#3].orders[&1].&", + "amount": "customers[#3].totalAmount" + } + } + } + }, + { + "operation": "modify-overwrite-beta", + "spec": { + "customers": { + "*": { + "id": "=firstElement(@(1,id))", + "name": "=firstElement(@(1,name))", + "totalAmount": "=intSum(@(1,totalAmount))" + } + } + } + } +] + + + +Output Json + +{ + "customers": [ + { + "id": "customer1", + "name": "John Smith", + "orders": [ + { + "id": "order1", + "date": "2022-01-01T00:00:00Z", + "items": [ + { + "id": "item1", + "name": "Product 1", + "price": 10, + "quantity": 2 + }, + { + "id": "item2", + "name": "Product 2", + "price": 20, + "quantity": 1 + } + ], + "totalPrice": 40 + }, + { + "id": "order2", + "date": "2022-02-01T00:00:00Z", + "items": [ + { + "id": "item3", + "name": "Product 3", + "price": 30, + "quantity": 3 + } + ], + "totalPrice": 90 + } + ], + "totalAmount": 130 + }, + { + "id": "customer2", + "name": "Jane Doe", + "orders": [ + { + "id": "order3", + "date": "2022-03-01T00:00:00Z", + "items": [ + { + "id": "item4", + "name": "Product 4", + "price": 40, + "quantity": 4 + } + ], + "totalPrice": 160 + } + ], + "totalAmount": 160 + } + ] +} \ No newline at end of file diff --git a/Module 5/Question 15/approach.md b/Module 5/Question 15/approach.md new file mode 100644 index 00000000..5e475104 --- /dev/null +++ b/Module 5/Question 15/approach.md @@ -0,0 +1,18 @@ +## Number of operation 4 +1. shift (3 times) +2. modify-overwrite-beta (1 times) +3. remove (1 times) +4. sort (1 times) + +## Explanation: + +* It shifts the values of the "orders" array under each "customerId" and creates a new "orders" array at the top level. + +* It shifts all the remaining key-value pairs under the top-level asterisk, which is the current object, and renames it as "customers". + +* It restructures the "customers" object to have nested "orders" arrays with their respective properties, and assigns the total order price to the "totalAmount" property. + +* It modifies the "customers" object by calculating the sum of "totalAmount" for each customer and assigns their respective "id". It also modifies the first customer's "name" to "John Doe" and the second customer's "name" to "Jane Doe". + +* It removes the "customerId" property from all orders. +It sorts the "customers" array alphabetically based on the customer's name. \ No newline at end of file diff --git a/Module 5/Question 16/Problem16.json b/Module 5/Question 16/Problem16.json new file mode 100644 index 00000000..27d75a6e --- /dev/null +++ b/Module 5/Question 16/Problem16.json @@ -0,0 +1,70 @@ +Input Json + +{ + "employees": [ + { + "id": "1001", + "name": "John Doe", + "age": 25, + "skills": [ + { + "name": "Java", + "level": "Intermediate" + }, + { + "name": "Python", + "level": "Expert" + } + ] + }, + { + "id": "1002", + "name": "Jane Doe", + "age": 30, + "skills": [ + { + "name": "Java", + "level": "Expert" + } + ] + } + ] +} + +Json Spec + +[ + { + "operation": "shift", + "spec": { + "employees": { + "*": { + "skills": { + "*": { + "@(2,name)": "@name.@level[]" + } + } + } + } + } + } +] + + +Output Json + +{ + "Java": { + "Intermediate": [ + "John Doe" + ], + "Expert": [ + "Jane Doe" + ] + }, + "Python": { + "Expert": [ + "John Doe" + ] + } +} \ No newline at end of file diff --git a/Module 5/Question 16/approach.md b/Module 5/Question 16/approach.md new file mode 100644 index 00000000..289a9692 --- /dev/null +++ b/Module 5/Question 16/approach.md @@ -0,0 +1,5 @@ +## Number Of Operation 1 +1. shift (1 times) + +## Explanation: +* It shifts the values of the "name" and "level" properties within each "skills" array and creates a new nested structure where the "name" becomes the key and the "level" becomes the value under each "skills" array. \ No newline at end of file diff --git a/Module 5/Question 17/Problem17.json b/Module 5/Question 17/Problem17.json new file mode 100644 index 00000000..06359d87 --- /dev/null +++ b/Module 5/Question 17/Problem17.json @@ -0,0 +1,62 @@ +Input Json +{ + "products": [ + { + "id": "1001", + "name": "Product 1", + "price": 10.99 + }, + { + "id": "1002", + "name": "Product 2", + "price": 15.99, + "available": true + }, + { + "id": "1003", + "name": "Product 3", + "price": 20.99, + "available": false + } + ] +} + +Json Spec + +[ + { + "operation": "modify-default-beta", + "spec": { + "products": { + "*": { + "available": false + } + } + } + } +] + +Output Json + +{ + "products": [ + { + "id": "1001", + "name": "Product 1", + "price": 10.99, + "available": false + }, + { + "id": "1002", + "name": "Product 2", + "price": 15.99, + "available": true + }, + { + "id": "1003", + "name": "Product 3", + "price": 20.99, + "available": false + } + ] +} \ No newline at end of file diff --git a/Module 5/Question 17/approach.md b/Module 5/Question 17/approach.md new file mode 100644 index 00000000..0bc50998 --- /dev/null +++ b/Module 5/Question 17/approach.md @@ -0,0 +1,5 @@ +## Number of operation 1 +1. modify-default-beta (1 times) + +## Explanation: +* It modifies the default value of the "available" property to false for all objects within the "products" array. This ensures that all products have the "available" property set to false, regardless of the original value provided. \ No newline at end of file diff --git a/Module 5/Question 18/Problem18.json b/Module 5/Question 18/Problem18.json new file mode 100644 index 00000000..4b5ffcdc --- /dev/null +++ b/Module 5/Question 18/Problem18.json @@ -0,0 +1,69 @@ +Input Json + +{ + "employees": [ + { + "name": "John", + "age": 30, + "salary": 5000 + }, + { + "name": "Jane", + "age": 35, + "salary": 6000 + }, + { + "name": "Bob", + "age": 40, + "salary": 7000 + } + ] +} + +Json Spec + +[ + { + "operation": "modify-overwrite-beta", + "spec": { + "employees": { + "*": { + "temp": "=divideAndRound(0,@(1,salary),10)", + "salary": "=doubleSum(@(1,temp),@(1,salary))" + } + } + } + }, + { + "operation": "remove", + "spec": { + "employees": { + "*": { + "temp": "" + } + } + } + } +] + +Output Json + +{ + "employees": [ + { + "name": "John", + "age": 30, + "salary": 5500.0 + }, + { + "name": "Jane", + "age": 35, + "salary": 6600.0 + }, + { + "name": "Bob", + "age": 40, + "salary": 7700.0 + } + ] +} \ No newline at end of file diff --git a/Module 5/Question 18/approach.md b/Module 5/Question 18/approach.md new file mode 100644 index 00000000..ffaf7db0 --- /dev/null +++ b/Module 5/Question 18/approach.md @@ -0,0 +1,8 @@ +## Number of operations 2 +1. modify-overwrite-beta (1 times) +2. remove (1 times) + +## Explanation: +* First it calculates a temporary value for each employee's salary by dividing the current salary by 10 and rounding the result. +then modifies the salary property for each employee by adding the temporary value to the original salary. +* At the end it removes the temporary property from each employee. \ No newline at end of file diff --git a/Module 5/Question 19/Problem19.json b/Module 5/Question 19/Problem19.json new file mode 100644 index 00000000..c198e429 --- /dev/null +++ b/Module 5/Question 19/Problem19.json @@ -0,0 +1,68 @@ +Input Json + +{ + "products": [ + { + "id": "1001", + "name": "Product 1", + "price": 10.99 + }, + { + "id": "1002", + "name": "Product 2", + "price": 15.99 + }, + { + "id": "1003", + "name": "Product 3", + "price": 20.99 + } + ] +} + +Json Spec + +[ + { + "operation": "modify-overwrite-beta", + "spec": { + "products": { + "*": { + "price": "=doubleSum(@(1,price),@(1,price))" + } + } + } + }, + { + "operation": "modify-overwrite-beta", + "spec": { + "products": { + "[0]": { + "price": "=divide(@(1,price),2)" + } + } + } + } +] + +Output Json + +{ + "products": [ + { + "id": "1001", + "name": "Product 1", + "price": 21.98 + }, + { + "id": "1002", + "name": "Product 2", + "price": 31.98 + }, + { + "id": "1003", + "name": "Product 3", + "price": 41.98 + } + ] +} \ No newline at end of file diff --git a/Module 5/Question 19/approach.md b/Module 5/Question 19/approach.md new file mode 100644 index 00000000..0f3412ac --- /dev/null +++ b/Module 5/Question 19/approach.md @@ -0,0 +1,6 @@ +## Number of operation 1 +1. Modify-overwrite-beta (2 times) + +## Explanation: +* It modifies the price property for each product by doubling the current price. +* It modifies the price property of the first product by dividing the current price by 2. \ No newline at end of file diff --git a/Module 5/Question 2/Problem2.json b/Module 5/Question 2/Problem2.json new file mode 100644 index 00000000..eb679aee --- /dev/null +++ b/Module 5/Question 2/Problem2.json @@ -0,0 +1,29 @@ +Input JSON + +{ + "name": "John", + "age": 35, + "city": "New York" +} + +JSON Spec + +[ + { + "operation": "shift", + "spec": { + "name": "Name", + "age": "Age", + "city": "City" + } + } +] + + +Output JSON + +{ + "Name": "John", + "Age": 35, + "City": "New York" +} \ No newline at end of file diff --git a/Module 5/Question 2/approach.md b/Module 5/Question 2/approach.md new file mode 100644 index 00000000..77ec85e1 --- /dev/null +++ b/Module 5/Question 2/approach.md @@ -0,0 +1,5 @@ +## Number of Operation 1 +1. shift (1 times) + +## Explation : + * In this I have used **shift** opration for converting the lower case into capital form. \ No newline at end of file diff --git a/Module 5/Question 20/Problem20.json b/Module 5/Question 20/Problem20.json new file mode 100644 index 00000000..d3a49008 --- /dev/null +++ b/Module 5/Question 20/Problem20.json @@ -0,0 +1,112 @@ +Input Json + +{ + "employees": [ + { + "name": "John", + "age": 30, + "department": { + "id": 1, + "name": "Sales" + } + }, + { + "name": "Jane", + "age": 35, + "department": { + "id": 2, + "name": "Marketing" + } + }, + { + "name": "Bob", + "age": 40, + "department": { + "id": 1, + "name": "Sales" + } + } + ] +} + +Json Spec + +[ + { + "operation": "shift", + "spec": { + "employees": { + "*": { + "@department": "departments.[&]", + "name": "departments[#2].employees.name", + "age": "departments[#2].employees.age" + } + } + } + }, + { + "operation": "shift", + "spec": { + "departments": { + "*": { + "id": "departments.@(1,id).id", + "name": "departments.@(1,id).name", + "employees": "departments.@(1,id).employees[]" + } + } + } + }, + { + "operation": "shift", + "spec": { + "departments": { + "*": "departments" + } + } + }, + { + "operation": "modify-overwrite-beta", + "spec": { + "departments": { + "*": { + "*": { + "employees": "&" + }, + "id": "@(1,id[0])", + "name": "@(1,name[0])" + } + } + } + } +] + +Output Json + + { + "departments": [ + { + "id": 1, + "name": "Sales", + "employees": [ + { + "name": "John", + "age": 30 + }, + { + "name": "Bob", + "age": 40 + } + ] + }, + { + "id": 2, + "name": "Marketing", + "employees": [ + { + "name": "Jane", + "age": 35 + } + ] + } + ] +} \ No newline at end of file diff --git a/Module 5/Question 20/approach.md b/Module 5/Question 20/approach.md new file mode 100644 index 00000000..f1d48f1f --- /dev/null +++ b/Module 5/Question 20/approach.md @@ -0,0 +1,10 @@ +## Number of operation 2 +1. shift (3 times) +2. modify-overwrite-beta (1 times) + +## Explanation: + +* It shifts the "name" and "age" properties of each employee under the corresponding "department" object and assigns them to the "departments" array. +* It shifts the "id", "name", and "employees" properties under each "department" object to create a nested structure in the "departments" array. +* It restructures the "departments" object to have a flattened structure by assigning the nested "departments" object to the top level. +* It modifies the "departments" object by assigning the "employees" array to each department, and assigns the first element of "id" and "name" arrays to the respective "id" and "name" properties. \ No newline at end of file diff --git a/Module 5/Question 21/Problem21.json b/Module 5/Question 21/Problem21.json new file mode 100644 index 00000000..fff8d01f --- /dev/null +++ b/Module 5/Question 21/Problem21.json @@ -0,0 +1,33 @@ +Input Json + +{ + "restaurant": { + "rating": { + "value": 3 + }, + "address": { + "value": "India" + } + } +} + +Json Spec + +[ + { + "operation": "shift", + "spec": { + "restaurant": { + "rating": { + "value": "Restaurant Rating" + } + } + } + } +] + +Output Json + +{ + "Restaurant Rating": 3 +} \ No newline at end of file diff --git a/Module 5/Question 21/approach.md b/Module 5/Question 21/approach.md new file mode 100644 index 00000000..94572c61 --- /dev/null +++ b/Module 5/Question 21/approach.md @@ -0,0 +1,6 @@ +## Number of operation 1 +1. shift (1 times) + +## Explanation + +* It shifts the value of the "value" property under "rating" and assigns it to a new property called "Restaurant Rating". \ No newline at end of file diff --git a/Module 5/Question 22/Problem22.json b/Module 5/Question 22/Problem22.json new file mode 100644 index 00000000..d0f918d7 --- /dev/null +++ b/Module 5/Question 22/Problem22.json @@ -0,0 +1,52 @@ +Input Json + +[ + { + "restaurant": { + "rating": { + "value": 9 + }, + "address": { + "value": "India" + } + } + }, + { + "restaurant": { + "rating": { + "value": 7 + }, + "address": { + "value": "United States" + } + } + } +] + +Json Spec + +[ + { + "operation": "shift", + "spec": { + "*": { + "restaurant": { + "rating": { + "value": "[#4].Restaurant Rating " + } + } + } + } + } +] + +Output Json + +[ + { + "Restaurant Rating ": 9 + }, + { + "Restaurant Rating ": 7 + } +] \ No newline at end of file diff --git a/Module 5/Question 22/approach.md b/Module 5/Question 22/approach.md new file mode 100644 index 00000000..c6859c00 --- /dev/null +++ b/Module 5/Question 22/approach.md @@ -0,0 +1,6 @@ +## Number of operation 1 +1. shift (1 times) + +## Explanation: + +* It shifts the value of the "value" property under "rating" for each object within the array and assigns it to a new property called "Restaurant Rating" at the corresponding index within the resulting array. \ No newline at end of file diff --git a/Module 5/Question 23/Problem23.json b/Module 5/Question 23/Problem23.json new file mode 100644 index 00000000..2f8140e2 --- /dev/null +++ b/Module 5/Question 23/Problem23.json @@ -0,0 +1,58 @@ +Input Json + +[ + { + "restaurant": { + "rating": { + "value": 9 + }, + "address": { + "value": "India" + } + } + }, + { + "restaurant": { + "rating": { + "value": 7 + }, + "address": { + "value": "United States" + } + } + } +] + +Json Spec + +[ + { + "operation": "shift", + "spec": { + "*": { + "restaurant": { + "rating": { + "value": "[#4].Restaurant Rating " + }, + "address": { + "value": "[#4].Restaurant Country" + } + } + } + } + } +] + + +Output Json + +[ + { + "Restaurant Rating ": 9, + "Restaurant Country": "India" + }, + { + "Restaurant Rating ": 7, + "Restaurant Country": "United States" + } +] \ No newline at end of file diff --git a/Module 5/Question 23/approach.md b/Module 5/Question 23/approach.md new file mode 100644 index 00000000..3871ed0c --- /dev/null +++ b/Module 5/Question 23/approach.md @@ -0,0 +1,7 @@ +## Number of operation 1 +1. shift (1 times) + +## Explanation: + +* It shifts the value of the "value" property under "rating" and assigns it to a new property called "Restaurant Rating" at the corresponding index within the resulting array. +* It shifts the value of the "value" property under "address" and assigns it to a new property called "Restaurant Country" at the corresponding index within the resulting array. \ No newline at end of file diff --git a/Module 5/Question 24/Problem24.json b/Module 5/Question 24/Problem24.json new file mode 100644 index 00000000..1d23c6d7 --- /dev/null +++ b/Module 5/Question 24/Problem24.json @@ -0,0 +1,99 @@ +Input Json + +[ + { + "restaurant": { + "rating": { + "value": 9 + }, + "address": { + "value": "India" + } + }, + "itemsList": [ + { + "itemName": "Example 11", + "itemPrice": 120 + }, + { + "itemName": "Example 12", + "itemPrice": 150 + } + ] + }, + { + "restaurant": { + "rating": { + "value": 7 + }, + "address": { + "value": "United States" + } + }, + "itemsList": [ + { + "itemName": "Example 21", + "itemPrice": 100 + }, + { + "itemName": "Example 22", + "itemPrice": 190 + } + ] + } +] + +Json Spec + +[ + { + "operation": "shift", + "spec": { + "*": { + "restaurant": { + "rating": { + "value": "[#4].Restaurant Rating " + }, + "address": { + "value": "[#4].Restaurant Country" + } + }, + "itemsList": { + "*": { + "itemName": "[#4].Dish Name", + "itemPrice": "[#4].Dish Price" + } + } + } + } + } +] + +Output Json + +[ + { + "Restaurant Rating ": 9, + "Restaurant Country": "India", + "Dish Name": [ + "Example 11", + "Example 12" + ], + "Dish Price": [ + 120, + 150 + ] + }, + { + "Restaurant Rating ": 7, + "Restaurant Country": "United States", + "Dish Name": [ + "Example 21", + "Example 22" + ], + "Dish Price": [ + 100, + 190 + ] + } +] \ No newline at end of file diff --git a/Module 5/Question 24/approach.md b/Module 5/Question 24/approach.md new file mode 100644 index 00000000..b17e2743 --- /dev/null +++ b/Module 5/Question 24/approach.md @@ -0,0 +1,7 @@ +## Number Of Operation 1 +1. shift (1 times) + +## Explanation: +* It shifts the value of the "value" property under "rating" and assigns it to a new property called "Restaurant Rating " at the corresponding index within the resulting array. +* It shifts the value of the "value" property under "address" and assigns it to a new property called "Restaurant Country" at the corresponding index within the resulting array. +* It shifts the values of "itemName" and "itemPrice" properties within the "itemsList" array and assigns them to new properties called "Dish Name" and "Dish Price" at the corresponding index within the resulting array. \ No newline at end of file diff --git a/Module 5/Question 25/Problem25.json b/Module 5/Question 25/Problem25.json new file mode 100644 index 00000000..54816e34 --- /dev/null +++ b/Module 5/Question 25/Problem25.json @@ -0,0 +1,104 @@ +Input Json + +[ + { + "restaurant": { + "rating": { + "value": 9 + }, + "address": { + "value": "India" + } + }, + "itemsList": [ + { + "itemName": "Example 11", + "itemPrice": 120 + }, + { + "itemName": "Example 12", + "itemPrice": 150 + } + ] + }, + { + "restaurant": { + "rating": { + "value": 7 + }, + "address": { + "value": "United States" + } + }, + "itemsList": [ + { + "itemName": "Example 21", + "itemPrice": 100 + }, + { + "itemName": "Example 22", + "itemPrice": 190 + } + ] + } +] + +Json Spec + +[ + { + "operation": "shift", + "spec": { + "*": { + "restaurant": { + "rating": { + "value": "[#4].Restaurant Rating " + }, + "address": { + "value": "[#4].Restaurant Country" + } + }, + "itemsList": { + "*": { + "itemName": "[#4].Dishes.[#2].Dish Name", + "itemPrice": "[#4].Dishes.[#2].Dish Price" + } + } + } + } + } +] + + +Output Json + +[ + { + "Restaurant Rating ": 9, + "Restaurant Country": "India", + "Dishes": [ + { + "Dish Name": "Example 11", + "Dish Price": 120 + }, + { + "Dish Name": "Example 12", + "Dish Price": 150 + } + ] + }, + { + "Restaurant Rating ": 7, + "Restaurant Country": "United States", + "Dishes": [ + { + "Dish Name": "Example 21", + "Dish Price": 100 + }, + { + "Dish Name": "Example 22", + "Dish Price": 190 + } + ] + } +] \ No newline at end of file diff --git a/Module 5/Question 25/approach.md b/Module 5/Question 25/approach.md new file mode 100644 index 00000000..08d1de0b --- /dev/null +++ b/Module 5/Question 25/approach.md @@ -0,0 +1,8 @@ +## Number Of approach 1 +1. shift (1 times) + + +## Explanation: +* It shifts the value of the "value" property under "rating" and assigns it to a new property called "Restaurant Rating " at the corresponding index within the resulting array. +* It shifts the value of the "value" property under "address" and assigns it to a new property called "Restaurant Country" at the corresponding index within the resulting array. +* It shifts the values of "itemName" and "itemPrice" properties within the "itemsList" array and assigns them to new properties called "Dish Name" and "Dish Price" at the corresponding index within the resulting array. The dishes are nested under a new property called "Dishes". diff --git a/Module 5/Question 26/Problem26.json b/Module 5/Question 26/Problem26.json new file mode 100644 index 00000000..0fa31e94 --- /dev/null +++ b/Module 5/Question 26/Problem26.json @@ -0,0 +1,59 @@ +Input Json + +[ + { + "returnId": "10051", + "returnQuantity": 2, + "returnPrice": 100, + "returnTax": 12.56 + }, + { + "returnId": "10052", + "returnQuantity": 25, + "returnPrice": 35, + "returnTax": 29.85 + } +] + +Json Spec + +[ + { + "operation": "modify-default-beta", + "spec": { + "*": { + "Return Id": "@(1,returnId)", + "temp": "=divide(1,@(1,returnQuantity))", + "Return Amount": "=divideAndRound(2,@(1,returnPrice),@(1,temp))", + "Return Total Amount": "=doubleSum(@(1,Return Amount),@(1,returnTax))" + } + } + }, + { + "operation": "remove", + "spec": { + "*": { + "returnId": "", + "returnQuantity": "", + "returnPrice": "", + "returnTax": "", + "temp": "" + } + } + } +] + +Output Json + +[ + { + "Return Id": "10051", + "Return Amount": 200.0, + "Return Total Amount": 212.56 + }, + { + "Return Id": "10052", + "Return Amount": 875.0, + "Return Total Amount": 904.85 + } +] \ No newline at end of file diff --git a/Module 5/Question 26/approach.md b/Module 5/Question 26/approach.md new file mode 100644 index 00000000..6f03b9fc --- /dev/null +++ b/Module 5/Question 26/approach.md @@ -0,0 +1,18 @@ +## Number of operation 2 +1. modify-default-beta (1 times) +2. remove (1 times) + +## Explanation: + +* It modifies the JSON structure by adding new properties and modifying existing properties. +* It calculates the values for the new properties based on the existing properties. +* It removes the existing properties that are no longer needed. +### Here's a breakdown of the transformation steps: + +* The "modify-default-beta" operation is used to add and calculate new properties: +* The "Return Id" property is set to the value of "returnId" from the input. +* The "temp" property is calculated by dividing 1 by the value of "returnQuantity". +* The "Return Amount" property is calculated by dividing 2 by the value of "returnPrice" and "temp". +* The "Return Total Amount" property is calculated by summing the values of "Return Amount" and "returnTax". +* The "remove" operation is used to remove the existing properties that are no longer needed: + "returnId", "returnQuantity", "returnPrice", "returnTax", and "temp" properties are removed from each object. \ No newline at end of file diff --git a/Module 5/Question 27/Problem27.json b/Module 5/Question 27/Problem27.json new file mode 100644 index 00000000..e3480ab3 --- /dev/null +++ b/Module 5/Question 27/Problem27.json @@ -0,0 +1,83 @@ +Input Json +[ + { + "returnId": "10051", + "returnQuantity": 2, + "returnPrice": 100, + "returnTax": 12.56, + "country": "USA" + }, + { + "returnId": "10052", + "returnQuantity": 25, + "returnPrice": 35, + "returnTax": 29.85, + "country": "CA" + }, + { + "returnId": "10053", + "returnQuantity": 5, + "returnPrice": 55, + "returnTax": 9.85, + "country": "" + } +] + +Json Spec + +[ + { + "operation": "modify-overwrite-beta", + "spec": { + "*": { + "Return Id": "@(1, returnId)", + "temp": "=divide(1,@(1,returnQuantity))", + "Return Amount": "=divide(@(1,returnPrice),@(1,temp))", + "Return Total Amount": "=doubleSum(@(1,Return Amount),@(1,returnTax))" + }, + "[0]": { + "Country": "United States of America" + }, + "[1]": { + "Country": "Canada" + }, + "[2]": { + "Country": "NA" + } + } + }, + { + "operation": "shift", + "spec": { + "*": { + "returnId": "[#2].Return Id", + "Return Amount": "[#2].Return Amount", + "Return Total Amount": "[#2].Return Total Amount", + "Country": "[#2].Country" + } + } + } +] + + Output Json + + [ + { + "Return Id": "10051", + "Return Amount": 200.0, + "Return Total Amount": 212.56, + "Country": "United States of America" + }, + { + "Return Id": "10052", + "Return Amount": 875.0, + "Return Total Amount": 904.85, + "Country": "Canada" + }, + { + "Return Id": "10053", + "Return Amount": 275.0, + "Return Total Amount": 284.85, + "Country": "NA" + } +] \ No newline at end of file diff --git a/Module 5/Question 27/approach.md b/Module 5/Question 27/approach.md new file mode 100644 index 00000000..9014ea61 --- /dev/null +++ b/Module 5/Question 27/approach.md @@ -0,0 +1,22 @@ +## Number of operation 2 +1. modify-overwrite-beta (1 times) +2. shift (1 times) + +## Explanation + +### The "modify-overwrite-beta" operation is used to add and calculate new properties: + +* The "Return Id" property is set to the value of "returnId" from the input. +* The "temp" property is calculated by dividing 1 by the value of "returnQuantity". +* The "Return Amount" property is calculated by dividing the value of "returnPrice" by "temp". +* The "Return Total Amount" property is calculated by summing the values of "Return Amount" and "returnTax". + +### The "modify-overwrite-beta" operation also replaces the values of the "country" property: + +* The value of "country" in the first object ("[0]") is replaced with "United States of America". +* The value of "country" in the second object ("[1]") is replaced with "Canada". +* The value of "country" in the third object ("[2]") is replaced with "NA". + +### The "shift" operation is used to restructure the JSON: + +* The property names are shifted to create a new array of objects with the desired property names ("Return Id", "Return Amount", "Return Total Amount", "Country"). \ No newline at end of file diff --git a/Module 5/Question 28/Problem28.json b/Module 5/Question 28/Problem28.json new file mode 100644 index 00000000..3e5715db --- /dev/null +++ b/Module 5/Question 28/Problem28.json @@ -0,0 +1,86 @@ +Input Json + +[ + { + "returnId": "151", + "returnItemAdjustments": [ + { + "returnItemSeqId": "00001", + "amount": 28.64, + "returnAdjustmentTypeId": "RET_SALES_TAX_ADJ", + "description": "Return Sales Tax", + "createdDate": null, + "returnId": "151", + "returnAdjustmentId": "", + "comments": "Return Sales Tax", + "shipGroupSeqId": null + }, + { + "returnItemSeqId": "00001", + "amount": 58.64, + "returnAdjustmentTypeId": "RET_SALES_TAX_ADJ", + "description": "Return Sales Tax", + "createdDate": null, + "returnId": "151", + "returnAdjustmentId": "", + "comments": "Return Sales Tax", + "shipGroupSeqId": null + } + ] + }, + { + "returnId": "152", + "returnItemAdjustments": [ + { + "returnItemSeqId": "00002", + "amount": 38.64, + "returnAdjustmentTypeId": "RET_SALES_TAX_ADJ", + "description": "Return Sales Tax", + "createdDate": null, + "returnId": "152", + "returnAdjustmentId": "", + "comments": "Return Sales Tax", + "shipGroupSeqId": null + } + ] + } +] + +Json Spec + +[ + { + "operation": "shift", + "spec": { + "*": { + "returnId": "[#2].returnId", + "returnItemAdjustments": { + "*": { + "amount": "[#4].returnTax" + } + } + } + } + }, + { + "operation": "modify-overwrite-beta", + "spec": { + "*": { + "returnTax": "=doubleSum(@(1,returnTax))" + } + } + } +] + +Output Json + +[ + { + "returnId": "151", + "returnTax": 87.28 + }, + { + "returnId": "152", + "returnTax": 38.64 + } +] \ No newline at end of file diff --git a/Module 5/Question 28/approach.md b/Module 5/Question 28/approach.md new file mode 100644 index 00000000..a7b138b2 --- /dev/null +++ b/Module 5/Question 28/approach.md @@ -0,0 +1,14 @@ +## Number of operation 2 +1. shift (1 times) +2. modify-overwrite-beta (1 times) + +## Explanation: + +### The "shift" operation is used to restructure the JSON: + +* The "returnId" property is shifted to create a new array of objects with the property name "returnId". +* The "amount" property under "returnItemAdjustments" is shifted to create a new array of objects with the property name "returnTax". + +### The "modify-overwrite-beta" operation is used to calculate the sum of "amount" values: + +* The "returnTax" property is overwritten with the calculated sum of "returnTax" values for each object. \ No newline at end of file diff --git a/Module 5/Question 29/Problem29.json b/Module 5/Question 29/Problem29.json new file mode 100644 index 00000000..9092a311 --- /dev/null +++ b/Module 5/Question 29/Problem29.json @@ -0,0 +1,43 @@ +Input Json + +{ + "person": { + "name": "John Doe", + "age": 30, + "address": { + "city": "New York", + "state": "NY" + } + } +} + +Json Spec + +[ + { + "operation": "shift", + "spec": { + "person": { + "*": "person-&" + } + } + }, + { + "operation": "shift", + "spec": { + "*": "&", + "person-address": { + "*": "person-address-&" + } + } + } +] + +Output Json + +{ + "person_name": "John Doe", + "person_age": 30, + "person_address_city": "New York", + "person_address_state": "NY" +} \ No newline at end of file diff --git a/Module 5/Question 29/approach.md b/Module 5/Question 29/approach.md new file mode 100644 index 00000000..1f626d09 --- /dev/null +++ b/Module 5/Question 29/approach.md @@ -0,0 +1,8 @@ +## Number of operation 2 + +1. shift (2 times) + +## Explanation: +* The first "shift" operation extracts all properties inside the "person" object and prefixes their names with "person-". For example, "name" becomes "person-name" and "age" becomes "person-age". + +* The second "shift" operation copies all properties from the root level and appends them to the resulting JSON. Additionally, it extracts properties inside the "person-address" object and prefixes their names with "person-address-". \ No newline at end of file diff --git a/Module 5/Question 3/Problem3.json b/Module 5/Question 3/Problem3.json new file mode 100644 index 00000000..d6efcca8 --- /dev/null +++ b/Module 5/Question 3/Problem3.json @@ -0,0 +1,35 @@ +Input JSON + +{ + "name": "John", + "age": 35, + "city": "New York", + "phone": "+1-555-123-4567" +} + + +JOLT Spec + +[ + { + "operation": "shift", + "spec": { + "name": "Name", + "age": "Age", + "city": "Contact.City", + "phone": "Contact.Phone" + } + } +] + + +Output JSON + +{ + "Name": "John", + "Age": 35, + "Contact": { + "City": "New York", + "Phone": "+1-555-123-4567" + } +} \ No newline at end of file diff --git a/Module 5/Question 3/approach.md b/Module 5/Question 3/approach.md new file mode 100644 index 00000000..92ab79ef --- /dev/null +++ b/Module 5/Question 3/approach.md @@ -0,0 +1,6 @@ +## Number of operations 1 +1. shift (1 times) + +## Explation: + +* In this is have used **shift** operation to capitalize the keys and also for creating/separating the contact details in contact key. \ No newline at end of file diff --git a/Module 5/Question 30/Problem30.json b/Module 5/Question 30/Problem30.json new file mode 100644 index 00000000..f293494b --- /dev/null +++ b/Module 5/Question 30/Problem30.json @@ -0,0 +1,44 @@ +Input Json + +{ + "person": { + "name": "John Doe", + "age": 30, + "address": { + "city": "New York", + "state": "NY" + } + }, + "employee": { + "name": "Jane Doe", + "salary": 50000, + "office": { + "city": "San Francisco", + "state": "CA" + } + } +} + +Json Spec + +[ + { + "operation": "shift", + "spec": { + "employee": { + "name": "name", + "office": { + "*": "office-&" + } + } + } + } +] + +Output Json + +{ + "name": "Jane Doe", + "office-city": "San Francisco", + "office-state": "CA" +} \ No newline at end of file diff --git a/Module 5/Question 30/approach.md b/Module 5/Question 30/approach.md new file mode 100644 index 00000000..8de68746 --- /dev/null +++ b/Module 5/Question 30/approach.md @@ -0,0 +1,8 @@ +## Number of operation 1 +1. shift (1 times) + +## Explanation: + +* The properties "name" and "office" under the "employee" object are extracted and mapped directly to the resulting JSON. +* The properties inside the "office" object are shifted and prefixed with "office-". +* The resulting JSON will have the properties "name", "office-city", and "office-state" extracted from the "employee" object. diff --git a/Module 5/Question 31/Problem31.json b/Module 5/Question 31/Problem31.json new file mode 100644 index 00000000..91255916 --- /dev/null +++ b/Module 5/Question 31/Problem31.json @@ -0,0 +1,76 @@ +Input Json + +{ + "items": [ + { + "id": "1", + "name": "Book", + "prices": [ + { + "currency": "USD", + "value": 10 + }, + { + "currency": "EUR", + "value": 8 + } + ] + }, + { + "id": "2", + "name": "Pen", + "prices": [ + { + "currency": "USD", + "value": 2 + }, + { + "currency": "EUR", + "value": 1.5 + } + ] + } + ] +} + +Json Spec + +[ + { + "operation": "modify-default-beta", + "spec": { + "items": { + "*": { + "prices": { + "*": { + "temp": "=concat(@(3,id),'_',@(1,currency))" + } + } + } + } + } + }, + { + "operation": "shift", + "spec": { + "items": { + "*": { + "prices": { + "*": { + "@value": "@temp" + } + } + } + } + } + } +] + +Output Json + +{ + "1_USD": 10, + "1_EUR": 8, + "2_USD": 2, + "2_EUR": 1.5 +} \ No newline at end of file diff --git a/Module 5/Question 31/approach.md b/Module 5/Question 31/approach.md new file mode 100644 index 00000000..486309c7 --- /dev/null +++ b/Module 5/Question 31/approach.md @@ -0,0 +1,8 @@ +## Number Of Operation 2 +1. modify-default-beta (1 times) +2. shift (1 times) + +## Explanation : +* The "modify-default-beta" operation is used to add a temporary property called "temp" to each item's prices array. The value of "temp" is generated by concatenating the item's "id" and the "currency" value of each price. +* The "shift" operation is used to restructure the JSON by mapping the "@value" of each price to the corresponding "@temp" property. +* As a result, the JSON will be transformed to have the "id_currency" format for each price value under the "items" array. \ No newline at end of file diff --git a/Module 5/Question 32/Problem32.json b/Module 5/Question 32/Problem32.json new file mode 100644 index 00000000..65af23db --- /dev/null +++ b/Module 5/Question 32/Problem32.json @@ -0,0 +1,54 @@ +Input Json + +{ + "data": [ + { + "x": "A", + "y": "1", + "value": 10 + }, + { + "x": "A", + "y": "2", + "value": 20 + }, + { + "x": "B", + "y": "1", + "value": 30 + }, + { + "x": "B", + "y": "2", + "value": 40 + } + ] +} + +Json Spec + +[ + { + "operation": "shift", + "spec": { + "data": { + "*": { + "@value": "@x.@y" + } + } + } + } +] + +Output Json + +{ + "A": { + "1": 10, + "2": 20 + }, + "B": { + "1": 30, + "2": 40 + } +} \ No newline at end of file diff --git a/Module 5/Question 32/approach.md b/Module 5/Question 32/approach.md new file mode 100644 index 00000000..7af46416 --- /dev/null +++ b/Module 5/Question 32/approach.md @@ -0,0 +1,7 @@ +## Number Of Operation 1 +1. shift (1 times) + +## Explanation: + +* The "shift" operation is used to restructure the JSON by mapping the "@value" of each object in the "data" array to the corresponding "@x.@y" property. +* As a result, the JSON will be transformed to have the "x.y" format for each value under the "data" array. diff --git a/Module 5/Question 33/Problem33.json b/Module 5/Question 33/Problem33.json new file mode 100644 index 00000000..8e9325dd --- /dev/null +++ b/Module 5/Question 33/Problem33.json @@ -0,0 +1,68 @@ +Input Json + +{ + "id": 1, + "name": "John", + "hobbies": [ + { + "name": "reading", + "level": "advanced" + }, + { + "name": "swimming", + "level": "beginner" + } + ] +} + + +Json Spec + +[ + { + "operation": "modify-overwrite-beta", + "spec": { + "hobbies": { + "*": { + "id": "@(3,id)", + "name": "@(3,name)", + "hobby_level": "@(1,level)", + "hobby_name": "@(1,name)" + } + } + } + }, + { + "operation": "shift", + "spec": { + "hobbies": { + "*": "[#1]" + } + } + }, + { + "operation": "remove", + "spec": { + "*": { + "level": "" + } + } + } +] + +Output Json + +[ + { + "name": "John", + "id": 1, + "hobby_level": "advanced", + "hobby_name": "John" + }, + { + "name": "John", + "id": 1, + "hobby_level": "beginner", + "hobby_name": "John" + } +] \ No newline at end of file diff --git a/Module 5/Question 33/approach.md b/Module 5/Question 33/approach.md new file mode 100644 index 00000000..0a36a8b9 --- /dev/null +++ b/Module 5/Question 33/approach.md @@ -0,0 +1,13 @@ +## Number of operation 3 +1. modify-overwrite-beta (1 times) +2. shift (1 times) +3. remove (1 times) + + +## Explanation: + +1. The "modify-overwrite-beta" operation is used to modify and overwrite the values in the "hobbies" array. Each hobby object is modified to include additional properties such as "id" and "name" from the top-level object, as well as "hobby_level" and "hobby_name" from the corresponding hobby object. +2. The "shift" operation is used to restructure the JSON. The "hobbies" array is shifted to create a new array of objects with the property name "#1". +3. The "remove" operation is used to remove the "level" property from each object in the JSON. + +* As a result, the JSON will be transformed to have the hobbies listed with additional properties and without the "level" property. \ No newline at end of file diff --git a/Module 5/Question 34/Problem34.json b/Module 5/Question 34/Problem34.json new file mode 100644 index 00000000..00e219f3 --- /dev/null +++ b/Module 5/Question 34/Problem34.json @@ -0,0 +1,54 @@ +Input Json + +{ + "name": "John", + "hobby_1": "reading", + "level_1": "advanced", + "hobby_2": "swimming", + "level_2": "beginner" +} + +Json Spec + +[ + { + "operation": "shift", + "spec": { + "name": "name", + "hobby_*": "hobbies[#2].&(0,1).name", + "level_*": "hobbies[#2].&(0,1).level" + } + }, + { + "operation": "shift", + "spec": { + "name": "name", + "hobbies": { + "*": { + "*": { + "name": "hobbies[#2].name", + "level": "hobbies[#2].level" + } + } + } + } + } +] + +Output Json + +{ + "name": "John", + "hobbies": [ + { + "1": { + "name": "reading", + "level": "advanced" + }, + "2": { + "name": "swimming", + "level": "beginner" + } + } + ] +} \ No newline at end of file diff --git a/Module 5/Question 34/approach.md b/Module 5/Question 34/approach.md new file mode 100644 index 00000000..1da88140 --- /dev/null +++ b/Module 5/Question 34/approach.md @@ -0,0 +1,12 @@ +## Number of operation 2 + +1. shift (2 times) + +## Explanation: + +The transformation involves following operations: + + +* `shift` : It selects the fields starting with the key "hobby_" and splits it into two parts after underscore, &(0,1) is used to access the 2nd part of splitted string and make it a key under hobbies array, same procedure is followed with the words starting with the level_. + +* `shift` : Another shift operation is used to remove indexes 0,1 from the hobbies list. \ No newline at end of file diff --git a/Module 5/Question 4/Problem4.json b/Module 5/Question 4/Problem4.json new file mode 100644 index 00000000..eaed4951 --- /dev/null +++ b/Module 5/Question 4/Problem4.json @@ -0,0 +1,45 @@ +Input JSON + +{ + "name": "John", + "age": 35, + "hobbies": [ + "reading", + "movies", + "travel" + ] +} + + +JSON Spec + +[ + { + "operation": "shift", + "spec": { + "name": "Name", + "age": "Age", + "hobbies": { + "*": "Hobbies[].Name" + } + } + } +] + +Output JSON + +{ + "Name": "John", + "Age": 35, + "Hobbies": [ + { + "Name": "reading" + }, + { + "Name": "movies" + }, + { + "Name": "travel" + } + ] +} \ No newline at end of file diff --git a/Module 5/Question 4/approach.md b/Module 5/Question 4/approach.md new file mode 100644 index 00000000..2d294ff3 --- /dev/null +++ b/Module 5/Question 4/approach.md @@ -0,0 +1,7 @@ +## Number of operation 1 +1. shift (1 times) + +## Explation: + +* In this I have used **shift** operation to capitalize the key and store the hobbies into a list of Hobbies with the key value pair +{"Name":"reading"}.. \ No newline at end of file diff --git a/Module 5/Question 5/Problem5.json b/Module 5/Question 5/Problem5.json new file mode 100644 index 00000000..0f5d8baf --- /dev/null +++ b/Module 5/Question 5/Problem5.json @@ -0,0 +1,45 @@ +Input JSON + +{ + "firstName": "John", + "lastName": "Doe", + "email": "johndoe@example.com", + "address": { + "street": "123 Main St", + "city": "Anytown", + "state": "CA", + "zip": "12345" + } +} + +JSON Spec + +[ + { + "operation": "modify-default-beta", + "spec": { + "fullName": "=concat(@(1,firstName),' ',@(1,lastName))", + "email": "email", + "city": "@(1,address.city)", + "zip": "@(1,address.zip)" + } + }, + { + "operation": "remove", + "spec": { + "firstName": "", + "lastName": "", + "address": "" + } + } +] + + +Output JSON + +{ + "email": "johndoe@example.com", + "fullName": "John Doe", + "city": "Anytown", + "zip": "12345" +} \ No newline at end of file diff --git a/Module 5/Question 5/approach.md b/Module 5/Question 5/approach.md new file mode 100644 index 00000000..d6ddf102 --- /dev/null +++ b/Module 5/Question 5/approach.md @@ -0,0 +1,9 @@ +## Number of operation 2 +1. modify-default-beta (1 times) +2. remove + +## Explation: + +* At first I have used **(modify-overwrite-beta)** operation to concat the address. + +* Then i have used the **remove** operation for deleting the unwanted field. \ No newline at end of file diff --git a/Module 5/Question 6/Problem6.json b/Module 5/Question 6/Problem6.json new file mode 100644 index 00000000..bb6f8ec3 --- /dev/null +++ b/Module 5/Question 6/Problem6.json @@ -0,0 +1,104 @@ +Input Json + +{ + "users": [ + { + "name": "John Doe", + "age": 35, + "address": { + "street": "123 Main St", + "city": "Anytown", + "state": "CA", + "zip": "12345" + }, + "hobbies": [ + { + "name": "reading", + "type": "indoor" + }, + { + "name": "hiking", + "type": "outdoor" + } + ] + }, + { + "name": "Jane Doe", + "age": 30, + "address": { + "street": "456 First St", + "city": "Othertown", + "state": "NY", + "zip": "67890" + }, + "hobbies": [ + { + "name": "swimming", + "type": "outdoor" + }, + { + "name": "painting", + "type": "indoor" + } + ] + } + ] +} + +Json Spec + +[ + { + "operation": "modify-overwrite-beta", + "spec": { + "users": { + "*": { + "Name": "@(1,name)", + "Address": "=concat(@(1,address.street),', ',@(1,address.city),', ',@(1,address.state),', ',@(1,address.zip))", + "hobbies": { + "*": { + "name": "@(1,name)" + } + } + } + } + } + }, + { + "operation": "shift", + "spec": { + "users": { + "*": { + "Name": "[#2].Name", + "Address": "[#2].Address", + "hobbies": { + "*": { + "name": "[#4].Hobbies" + } + } + } + } + } + } +] + +Output Json + +[ + { + "Name": "John Doe", + "Address": "123 Main St, Anytown, CA, 12345", + "Hobbies": [ + "reading", + "hiking" + ] + }, + { + "Name": "Jane Doe", + "Address": "456 First St, Othertown, NY, 67890", + "Hobbies": [ + "swimming", + "painting" + ] + } +] \ No newline at end of file diff --git a/Module 5/Question 6/approach.md b/Module 5/Question 6/approach.md new file mode 100644 index 00000000..63f03fcf --- /dev/null +++ b/Module 5/Question 6/approach.md @@ -0,0 +1,7 @@ +## Number of oprations 2 +1. modify-overwrite-beta (1 times) +2. shift (1 times) + +## Explanation: +* The first operation **(modify-overwrite-beta)** I have used to concat the address and overwrite the key Address. +* In the second operation **(shift)** is used to structure the object properly as per the required output. \ No newline at end of file diff --git a/Module 5/Question 7/Problem7.json b/Module 5/Question 7/Problem7.json new file mode 100644 index 00000000..8f925e1d --- /dev/null +++ b/Module 5/Question 7/Problem7.json @@ -0,0 +1,69 @@ +Input JSON + +{ + "students": [ + { + "name": "John Doe", + "age": 23, + "email": "john.doe@example.com" + }, + { + "name": "Jane Smith", + "age": 25, + "email": "jane.smith@example.com" + } + ] +} + + +JSON Spec + +[ + { + "operation": "shift", + "spec": { + "students": { + "*": "[&]" + } + } + }, + { + "operation": "modify-default-beta", + "spec": { + "*": { + "Name": "@(1,name)", + "Age": "@(1,age)", + "temp": "=split('@', @(1,email))", + "Domain": "=lastElement(@(1,temp))" + } + } + }, + { + "operation": "remove", + "spec": { + "*": { + "name": "", + "age": "", + "temp": "", + "email": "" + } + } + } +] + + +Output JSON + + +[ + { + "Name": "John Doe", + "Age": 23, + "Domain": "example.com" + }, + { + "Name": "Jane Smith", + "Age": 25, + "Domain": "example.com" + } +] \ No newline at end of file diff --git a/Module 5/Question 7/approach.md b/Module 5/Question 7/approach.md new file mode 100644 index 00000000..d0d87ea8 --- /dev/null +++ b/Module 5/Question 7/approach.md @@ -0,0 +1,11 @@ +## Number of operations 3 +1. shift (1 times) +2. modify-default-beta (1 times) +3. remove (1 times) + +## Explanation: +* In this the first opertaion **(shift)** is used to create a list and remove the student. + +* Second operation **(modify-default-beta)** is used to split the email to get the domain. And created a new key Name, Age, Domain. + +* At last **remove** operation is used to remove the unwanted fields and all the temp. \ No newline at end of file diff --git a/Module 5/Question 8/Problem8.json b/Module 5/Question 8/Problem8.json new file mode 100644 index 00000000..e982f78c --- /dev/null +++ b/Module 5/Question 8/Problem8.json @@ -0,0 +1,109 @@ +Input Json +{ + "employees": [ + { + "name": "John Doe", + "salary": 50000, + "department": "Sales" + }, + { + "name": "Jane Smith", + "salary": 60000 + }, + { + "name": "Bob Johnson", + "department": "IT" + } + ] +} + + +Json spec +[ + { + "operation": "default", + "spec": { + "employees[]": { + "*": { + "department": "Marketing", + "salary": 45000 + } + } + } + }, + { + "operation": "shift", + "spec": { + "employees": { + "*": { + "*": "employees.[&1].&", + "department": { + "Marketing": { + "#40": "employees.[#4].bonus" + }, + "*": { + "#50": "employees.[#4].bonus" + } + } + } + } + } + }, + { + "operation": "modify-overwrite-beta", + "spec": { + "employees": { + "*": { + "bonus": "=divide(@(1,salary),@(1,bonus))" + } + } + } + }, + { + "operation": "shift", + "spec": { + "employees": { + "*": { + "@": "employees[&1]", + "@bonus": "totalBonus" + } + } + } + }, + { + "operation": "modify-overwrite-beta", + "spec": { + "employees": { + "*": { + "bonus": "=toInteger" + } + }, + "totalBonus": "=intSum(@(1,totalBonus))" + } + } +] + + + +Output Json + +{ + "employees": [ + { + "name": "John Doe", + "salary": 50000, + "bonus": 1000 + }, + { + "name": "Jane Smith", + "salary": 60000, + "bonus": 1500 + }, + { + "name": "Bob Johnson", + "bonus": 900, + "salary": 45000 + } + ], + "totalBonus": 3400 +} \ No newline at end of file diff --git a/Module 5/Question 8/approach.md b/Module 5/Question 8/approach.md new file mode 100644 index 00000000..dc829666 --- /dev/null +++ b/Module 5/Question 8/approach.md @@ -0,0 +1,12 @@ +## Number of operation 3 +1. modify-default-beta (1 times) +2. shift (1 times) +3. modify-overwrite-beta (1 times) + +## Explanation: + +* In first operation **(modify-default-beta)** is used to add the `bonus` field in each and every object of employees. + +* Second operation **(shift)** is used to structure the output correctly and create a list which contains all the bonus. + +* At last **(modify-overwrite-beta)** is used to add the bonus and store it into tatal bonus variable. \ No newline at end of file diff --git a/Module 5/Question 9/Problem9.json b/Module 5/Question 9/Problem9.json new file mode 100644 index 00000000..7c0fc93a --- /dev/null +++ b/Module 5/Question 9/Problem9.json @@ -0,0 +1,38 @@ +Input Json + +{ + "name": "John", + "age": 30, + "address": { + "street": "123 Main St", + "city": "Anytown", + "state": "CA", + "zip": "12345" + } +} + +Json Spec + +[ + { + "operation": "remove", + "spec": { + "address": { + "state": "" + } + } + } +] + + +Output Json + +{ + "name": "John", + "age": 30, + "address": { + "street": "123 Main St", + "city": "Anytown", + "zip": "12345" + } +} \ No newline at end of file diff --git a/Module 5/Question 9/approach.md b/Module 5/Question 9/approach.md new file mode 100644 index 00000000..c0b92af3 --- /dev/null +++ b/Module 5/Question 9/approach.md @@ -0,0 +1,5 @@ +## Number of operation 1 +1. remove (1 times) + +## Explanation: +* Only one **(remove)** operation is used to remove state from address object. \ No newline at end of file