Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

121 json command - parsing variables from json file #141

Merged
merged 15 commits into from
Dec 6, 2024

Conversation

thorinaboenke
Copy link
Contributor

@thorinaboenke thorinaboenke commented Dec 3, 2024

relates to Issue #121

  • adds a JsonCommand and JsonExecutor to load variables from a json file into the VariableStore
    this sample file:
{
  "first_list" : [1,2,3],
  "user": {
    "name": "John Doe",
    "age": 30,
    "address": {
      "street": "123 Main St",
      "city": "New York",
      "postal_codes": [10001, 10002]
    },
    "friends": [
      {
        "name": "Jane Smith",
        "age": 28,
        "address": {
          "street": "456 Oak Rd",
          "city": "Los Angeles",
          "postal_codes": [90001, 90002]
        }
      },
      {
        "name": "Emily Davis",
        "age": 35,
        "address": {
          "street": "789 Pine Ln",
          "city": "Chicago",
          "postal_codes": [60007, 60008]
        }
      }
    ]
  },
  "company": {
    "name": "TechCorp",
    "employees": [
      {
        "name": "Michael Johnson",
        "role": "Developer",
        "projects": ["App1", "App2"],
        "contact": {
          "email": "[email protected]",
          "phone": "+1-555-1234"
        }
      },
      {
        "name": "Sarah Brown",
        "role": "Manager",
        "projects": ["App3", "App4"],
        "contact": {
          "email": "[email protected]",
          "phone": "+1-555-5678"
        }
      }
    ]
  },
  "orders": [
    {
      "order_id": 1001,
      "items": [
        {"item": "Laptop", "quantity": 1, "price": 1200},
        {"item": "Mouse", "quantity": 1, "price": 25}
      ],
      "shipping": {
        "address": "123 Main St, New York, NY",
        "method": "FedEx",
        "tracking_number": "1234567890"
      }
    },
    {
      "order_id": 1002,
      "items": [
        {"item": "Smartphone", "quantity": 2, "price": 700},
        {"item": "Headphones", "quantity": 1, "price": 100}
      ],
      "shipping": {
        "address": "456 Oak Rd, Los Angeles, CA",
        "method": "UPS",
        "tracking_number": "9876543210"
      }
    }
  ]
}

results in the following variables in the var store:

[
    {
        "USER_NAME": "John Doe",
        "USER_AGE": "30",
        "USER_ADDRESS_STREET": "123 Main St",
        "USER_ADDRESS_CITY": "New York",
        "USER_FRIENDS_0_NAME": "Jane Smith",
        "USER_FRIENDS_0_AGE": "28",
        "USER_FRIENDS_0_ADDRESS_STREET": "456 Oak Rd",
        "USER_FRIENDS_0_ADDRESS_CITY": "Los Angeles",
        "USER_FRIENDS_1_NAME": "Emily Davis",
        "USER_FRIENDS_1_AGE": "35",
        "USER_FRIENDS_1_ADDRESS_STREET": "789 Pine Ln",
        "USER_FRIENDS_1_ADDRESS_CITY": "Chicago",
        "COMPANY_NAME": "TechCorp",
        "COMPANY_EMPLOYEES_0_NAME": "Michael Johnson",
        "COMPANY_EMPLOYEES_0_ROLE": "Developer",
        "COMPANY_EMPLOYEES_0_CONTACT_EMAIL": "[email protected]",
        "COMPANY_EMPLOYEES_0_CONTACT_PHONE": "+1-555-1234",
        "COMPANY_EMPLOYEES_1_NAME": "Sarah Brown",
        "COMPANY_EMPLOYEES_1_ROLE": "Manager",
        "COMPANY_EMPLOYEES_1_CONTACT_EMAIL": "[email protected]",
        "COMPANY_EMPLOYEES_1_CONTACT_PHONE": "+1-555-5678",
        "ORDERS_0_ORDER_ID": "1001",
        "ORDERS_0_ITEMS_0_ITEM": "Laptop",
        "ORDERS_0_ITEMS_0_QUANTITY": "1",
        "ORDERS_0_ITEMS_0_PRICE": "1200",
        "ORDERS_0_ITEMS_1_ITEM": "Mouse",
        "ORDERS_0_ITEMS_1_QUANTITY": "1",
        "ORDERS_0_ITEMS_1_PRICE": "25",
        "ORDERS_0_SHIPPING_ADDRESS": "123 Main St, New York, NY",
        "ORDERS_0_SHIPPING_METHOD": "FedEx",
        "ORDERS_0_SHIPPING_TRACKING_NUMBER": "1234567890",
        "ORDERS_1_ORDER_ID": "1002",
        "ORDERS_1_ITEMS_0_ITEM": "Smartphone",
        "ORDERS_1_ITEMS_0_QUANTITY": "2",
        "ORDERS_1_ITEMS_0_PRICE": "700",
        "ORDERS_1_ITEMS_1_ITEM": "Headphones",
        "ORDERS_1_ITEMS_1_QUANTITY": "1",
        "ORDERS_1_ITEMS_1_PRICE": "100",
        "ORDERS_1_SHIPPING_ADDRESS": "456 Oak Rd, Los Angeles, CA",
        "ORDERS_1_SHIPPING_METHOD": "UPS",
        "ORDERS_1_SHIPPING_TRACKING_NUMBER": "9876543210",
    },
    {
        "FIRST_LIST": [1, 2, 3],
        "USER_ADDRESS_POSTAL_CODES": [10001, 10002],
        "USER_FRIENDS_0_ADDRESS_POSTAL_CODES": [90001, 90002],
        "USER_FRIENDS_1_ADDRESS_POSTAL_CODES": [60007, 60008],
        "COMPANY_EMPLOYEES_0_PROJECTS": ["App1", "App2"],
        "COMPANY_EMPLOYEES_1_PROJECTS": ["App3", "App4"],
    },
]

@whotwagner Can you please confirm if this is what you wanted? OR should every value end up as a variable, i.e.

"COMPANY_EMPLOYEES_0_PROJECTS_0": "App1"
instead of
"COMPANY_EMPLOYEES_0_PROJECTS": ["App1", "App2"],

@thorinaboenke thorinaboenke marked this pull request as draft December 3, 2024 14:33
@thorinaboenke thorinaboenke changed the base branch from main to development December 4, 2024 13:59
@thorinaboenke thorinaboenke marked this pull request as ready for review December 4, 2024 14:49
@thorinaboenke thorinaboenke changed the title 121 json command - parsind variables from json file 121 json command - parsing variables from json file Dec 4, 2024
@whotwagner
Copy link
Contributor

@whotwagner Can you please confirm if this is what you wanted? OR should every value end up as a variable, i.e.

"COMPANY_EMPLOYEES_0_PROJECTS_0": "App1" instead of "COMPANY_EMPLOYEES_0_PROJECTS": ["App1", "App2"],

I think that we go with: lists at the end instead of creating string-variables for every item.

@whotwagner whotwagner merged commit 93235bc into ait-testbed:development Dec 6, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants