QAPI
  • Introduction to Qyrus
  • User Onboarding
  • API Onboarding
  • Build and Test Management
  • Environments and Certificates
  • Test Execution
    • Performance run
    • Schedule Runs
    • Functional run
    • Reports
  • Guides
    • 🚩CORS, CSP and Preview API
    • Introduction to API Testing
    • Getting Started with API Testing
    • Key Screens
    • Guide to JSON in API Testing
Powered by GitBook
On this page
  • Overview of JSON Structure
  • Objects
  • Arrays
  • Understanding Key/Value Pairs
  • Navigating JSON Paths
  • Best Practices for API Testing with JSON

Was this helpful?

  1. Guides

Guide to JSON in API Testing

JSON (JavaScript Object Notation) serves as a standard format for exchanging data, particularly in web APIs. Its readability for both humans and machines makes it essential for API testing.

Overview of JSON Structure

JSON is primarily built on two structures:

Objects

Objects in JSON are collections of key/value pairs, enclosed in curly braces {}. Each key (a string) is followed by a colon : and then the corresponding value, which could be of various types.

Example:

{
    "firstName": "Jane",
    "lastName": "Doe",
    "age": 28,
    "married": true
}

Arrays

Arrays are ordered lists of values, enclosed in square brackets []. They can contain any type of items, including numbers, strings, objects, or even other arrays.

Example:

["red", "green", "blue"]

Understanding Key/Value Pairs

  • Keys must be strings and are case-sensitive.

  • Values can be of types such as string, number, object, array, boolean, or null.

Navigating JSON Paths

To extract data from JSON, you'll need to understand its paths. Paths express the keys and indexes to navigate through the JSON structure.

Example JSON structure for reference:

{
    "user": {
        "personalInfo": {
            "name": "John",
            "age": 30,
            "city": "New York"
        },
        "preferences": {
            "food": "Italian",
            "color": "Blue"
        }
    }
}

To get the user's city, the JSON path would be .user.personalInfo.city.

Best Practices for API Testing with JSON

  1. Ensure Case Sensitivity: JSON keys are case-sensitive, so be precise with the casing.

  2. Structure Validation: Always check that the JSON structure meets the expected schema.

  3. Array Handling: Remember that JSON arrays start at index 0.

  4. Dealing with Nulls: Ensure your testing can handle cases where values may be null.

  5. Complex Structures: Be adept at navigating through nested JSON structures to find the necessary data.

By mastering JSON structure and paths, you will significantly improve your API testing efficacy, ensuring data is accurately transmitted and received.

PreviousKey Screens

Was this helpful?