Examples
This section provides practical examples of using the JSON Diff Tool for various real-world scenarios. Each example demonstrates different aspects of JSON comparison and change detection.
User Data Comparison
Scenario: User Profile Updates
Compare user profile data before and after updates to track changes in user information.
JSON A (Original Profile)
{
"id": 12345,
"name": "John Doe",
"email": "john.doe@example.com",
"age": 28,
"address": {
"street": "123 Main St",
"city": "New York",
"state": "NY",
"zipCode": "10001"
},
"preferences": {
"theme": "light",
"notifications": true,
"language": "en"
},
"hobbies": ["reading", "swimming", "photography"]
}
JSON B (Updated Profile)
{
"id": 12345,
"name": "John Smith",
"email": "john.smith@example.com",
"age": 29,
"address": {
"street": "456 Oak Ave",
"city": "Boston",
"state": "MA",
"zipCode": "02101"
},
"preferences": {
"theme": "dark",
"notifications": false,
"language": "en"
},
"hobbies": ["reading", "swimming", "photography", "cooking"],
"lastUpdated": "2024-01-15T10:30:00Z"
}
Expected Results
- Modified: name, email, age, address (all fields), preferences.theme, preferences.notifications
- Added: lastUpdated, hobbies3 (cooking)
- Unchanged: id, preferences.language, hobbies0-2
API Response Comparison
Scenario: API Version Changes
Compare API responses between different versions to identify breaking changes and new features.
JSON A (API v1.0)
{
"status": "success",
"code": 200,
"data": {
"users": [
{
"id": 1,
"name": "Alice Johnson",
"role": "admin",
"permissions": ["read", "write"]
},
{
"id": 2,
"name": "Bob Smith",
"role": "user",
"permissions": ["read"]
}
],
"total": 2,
"page": 1
},
"message": "Users retrieved successfully"
}
JSON B (API v2.0)
{
"status": "success",
"code": 200,
"data": {
"users": [
{
"id": 1,
"name": "Alice Johnson",
"role": "admin",
"permissions": ["read", "write", "delete"],
"lastLogin": "2024-01-15T09:15:00Z",
"isActive": true
},
{
"id": 2,
"name": "Bob Smith",
"role": "user",
"permissions": ["read"],
"lastLogin": "2024-01-14T16:45:00Z",
"isActive": true
},
{
"id": 3,
"name": "Carol Davis",
"role": "moderator",
"permissions": ["read", "moderate"],
"lastLogin": "2024-01-15T08:30:00Z",
"isActive": true
}
],
"total": 3,
"page": 1,
"limit": 10,
"hasMore": false
},
"message": "Users retrieved successfully",
"version": "2.0",
"timestamp": "2024-01-15T10:00:00Z"
}
Expected Results
- Modified: data.users0.permissions, data.users1.permissions, data.total
- Added: data.users0.lastLogin, data.users0.isActive, data.users1.lastLogin, data.users1.isActive, data.users2 (entire new user), data.limit, data.hasMore, version, timestamp
- Unchanged: status, code, data.page, message
Configuration File Comparison
Scenario: Application Configuration Changes
Compare application configuration files to track environment-specific changes and updates.
JSON A (Development Config)
{
"app": {
"name": "MyApp",
"version": "1.0.0",
"environment": "development",
"debug": true
},
"database": {
"host": "localhost",
"port": 5432,
"name": "myapp_dev",
"ssl": false
},
"api": {
"baseUrl": "http://localhost:3000",
"timeout": 5000,
"retries": 3
},
"logging": {
"level": "debug",
"file": "logs/dev.log"
}
}
JSON B (Production Config)
{
"app": {
"name": "MyApp",
"version": "1.0.0",
"environment": "production",
"debug": false
},
"database": {
"host": "prod-db.example.com",
"port": 5432,
"name": "myapp_prod",
"ssl": true,
"pool": {
"min": 5,
"max": 20
}
},
"api": {
"baseUrl": "https://api.myapp.com",
"timeout": 10000,
"retries": 5,
"rateLimit": {
"windowMs": 900000,
"max": 100
}
},
"logging": {
"level": "info",
"file": "logs/prod.log",
"rotation": {
"maxSize": "10MB",
"maxFiles": 5
}
},
"monitoring": {
"enabled": true,
"endpoint": "https://monitoring.myapp.com"
}
}
Expected Results
- Modified: app.environment, app.debug, database.host, database.name, database.ssl, api.baseUrl, api.timeout, api.retries, logging.level, logging.file
- Added: database.pool, api.rateLimit, logging.rotation, monitoring
- Unchanged: app.name, app.version, database.port
Data Migration Comparison
Scenario: Database Schema Migration
Compare data structures before and after database schema migrations to ensure data integrity.
JSON A (Before Migration)
{
"users": [
{
"user_id": 1,
"username": "alice",
"email_address": "alice@example.com",
"created_at": "2023-01-15",
"profile_data": {
"first_name": "Alice",
"last_name": "Johnson",
"phone": "+1-555-0123"
}
},
{
"user_id": 2,
"username": "bob",
"email_address": "bob@example.com",
"created_at": "2023-02-20",
"profile_data": {
"first_name": "Bob",
"last_name": "Smith",
"phone": "+1-555-0456"
}
}
]
}
JSON B (After Migration)
{
"users": [
{
"id": 1,
"username": "alice",
"email": "alice@example.com",
"createdAt": "2023-01-15T00:00:00Z",
"profile": {
"firstName": "Alice",
"lastName": "Johnson",
"phoneNumber": "+1-555-0123",
"displayName": "Alice Johnson"
},
"metadata": {
"migratedAt": "2024-01-15T10:00:00Z",
"migrationVersion": "2.0"
}
},
{
"id": 2,
"username": "bob",
"email": "bob@example.com",
"createdAt": "2023-02-20T00:00:00Z",
"profile": {
"firstName": "Bob",
"lastName": "Smith",
"phoneNumber": "+1-555-0456",
"displayName": "Bob Smith"
},
"metadata": {
"migratedAt": "2024-01-15T10:00:00Z",
"migrationVersion": "2.0"
}
}
]
}
Expected Results
- Modified: users0.user_id → users0.id, users0.email_address → users0.email, users0.created_at → users0.createdAt, users0.profile_data → users0.profile, users1 (same changes)
- Added: users0.profile.displayName, users0.metadata, users1.profile.displayName, users1.metadata
- Unchanged: users0.username, users1.username
Array Comparison Examples
Scenario: Shopping Cart Changes
Compare shopping cart contents to track item additions, removals, and quantity changes.
JSON A (Original Cart)
{
"cartId": "cart_123",
"items": [
{
"productId": "prod_001",
"name": "Laptop",
"price": 999.99,
"quantity": 1
},
{
"productId": "prod_002",
"name": "Mouse",
"price": 29.99,
"quantity": 2
}
],
"total": 1059.97,
"currency": "USD"
}
JSON B (Updated Cart)
{
"cartId": "cart_123",
"items": [
{
"productId": "prod_001",
"name": "Laptop",
"price": 899.99,
"quantity": 1
},
{
"productId": "prod_002",
"name": "Mouse",
"price": 29.99,
"quantity": 3
},
{
"productId": "prod_003",
"name": "Keyboard",
"price": 79.99,
"quantity": 1
}
],
"total": 1089.96,
"currency": "USD",
"discount": {
"code": "SAVE10",
"amount": 108.996
}
}
Expected Results
- Modified: items0.price, items1.quantity, total
- Added: items2 (new keyboard item), discount
- Unchanged: cartId, items0.productId, items0.name, items0.quantity, items1.productId, items1.name, items1.price, currency
Type Change Examples
Scenario: Data Type Evolution
Compare JSON objects where values change between different data types.
JSON A (String-based IDs)
{
"user": {
"id": "12345",
"age": "25",
"isActive": "true",
"score": "95.5",
"tags": "admin,premium,verified"
}
}
JSON B (Typed Values)
{
"user": {
"id": 12345,
"age": 25,
"isActive": true,
"score": 95.5,
"tags": ["admin", "premium", "verified"]
}
}
Expected Results
- Type Changes: id (string → number), age (string → number), isActive (string → boolean), score (string → number), tags (string → array)
- Unchanged: All property names and logical values
Complex Nested Comparison
Scenario: Multi-level Object Changes
Compare deeply nested objects with changes at multiple levels.
JSON A (Complex Structure)
{
"company": {
"info": {
"name": "TechCorp",
"founded": 2020,
"employees": 50
},
"departments": {
"engineering": {
"head": "Alice",
"size": 20,
"projects": ["Project A", "Project B"]
},
"marketing": {
"head": "Bob",
"size": 10,
"campaigns": ["Campaign 1"]
}
},
"settings": {
"timezone": "UTC",
"language": "en"
}
}
}
JSON B (Updated Structure)
{
"company": {
"info": {
"name": "TechCorp Inc.",
"founded": 2020,
"employees": 75,
"revenue": 1000000
},
"departments": {
"engineering": {
"head": "Alice",
"size": 30,
"projects": ["Project A", "Project B", "Project C"],
"budget": 500000
},
"marketing": {
"head": "Carol",
"size": 15,
"campaigns": ["Campaign 1", "Campaign 2"]
},
"sales": {
"head": "David",
"size": 20,
"targets": ["Q1", "Q2", "Q3", "Q4"]
}
},
"settings": {
"timezone": "PST",
"language": "en",
"currency": "USD"
}
}
}
Expected Results
- Modified: company.info.name, company.info.employees, company.departments.engineering.size, company.departments.engineering.projects, company.departments.marketing.head, company.departments.marketing.size, company.departments.marketing.campaigns, company.settings.timezone
- Added: company.info.revenue, company.departments.engineering.budget, company.departments.sales, company.settings.currency
- Unchanged: company.info.founded, company.departments.engineering.head, company.settings.language
Best Practices for Examples
Creating Effective Comparisons
- Use Real Data: Base examples on actual use cases from your projects
- Show Progression: Demonstrate how data evolves over time
- Include Edge Cases: Show how the tool handles unusual scenarios
- Document Expectations: Clearly state what changes should be detected
Learning from Examples
- Start Simple: Begin with basic object comparisons
- Progress to Complex: Gradually work with more complex nested structures
- Test Edge Cases: Try different data types and structures
- Save Important Examples: Use history to save useful comparison patterns
These examples demonstrate the versatility of the JSON Diff Tool across various scenarios, from simple data updates to complex system migrations. Use them as starting points for your own comparisons and adapt them to your specific needs.