JSON-Beispiele

Häufige JSON-Strukturen, mit einem Klick kopieren

Was ist JSON?

JSON (JavaScript Object Notation) ist ein leichtgewichtiges Datenaustauschformat. Es basiert auf der JavaScript-Objektsyntax, ist aber sprachunabhängig und in nahezu allen modernen Sprachen verfügbar.

JSON hat folgende Eigenschaften:

  • Für Menschen gut les- und schreibbar
  • Für Maschinen leicht zu parsen und zu erzeugen
  • Textbasiert und sprachunabhängig
  • Weit verbreitet für Datentransfer im Web

Einfaches Objekt

Grundlegende JSON-Struktur

{
  "name": "John Doe",
  "age": 30,
  "city": "New York"
}

Nutzerprofil

Benutzerinfos mit verschachtelten Objekten

{
  "id": 1,
  "name": "Alice Smith",
  "email": "alice@example.com",
  "profile": {
    "avatar": "https://example.com/avatar.jpg",
    "bio": "Software Developer",
    "location": "San Francisco"
  },
  "preferences": {
    "theme": "dark",
    "notifications": true
  }
}

Produktliste

JSON-Array mit mehreren Produktobjekten

[
  {
    "id": "p001",
    "name": "Laptop",
    "price": 999.99,
    "category": "Electronics",
    "inStock": true
  },
  {
    "id": "p002",
    "name": "Mouse",
    "price": 29.99,
    "category": "Accessories",
    "inStock": false
  }
]

API-Response

Typisches REST-Antwortformat

{
  "status": "success",
  "code": 200,
  "message": "Data retrieved successfully",
  "data": {
    "users": [
      {
        "id": 1,
        "name": "John",
        "role": "admin"
      },
      {
        "id": 2,
        "name": "Jane",
        "role": "user"
      }
    ],
    "pagination": {
      "page": 1,
      "limit": 10,
      "total": 25
    }
  },
  "timestamp": "2024-01-01T12:00:00Z"
}

Konfigurationsdatei

Anwendungskonfiguration in JSON

{
  "app": {
    "name": "MyApp",
    "version": "1.2.0",
    "environment": "production"
  },
  "database": {
    "host": "localhost",
    "port": 5432,
    "name": "myapp_db",
    "ssl": true
  },
  "features": {
    "authentication": true,
    "logging": true,
    "analytics": false
  }
}

Verschachteltes Array

Komplexe, mehrstufige Struktur

{
  "company": "Tech Corp",
  "departments": [
    {
      "name": "Engineering",
      "teams": [
        {
          "name": "Frontend",
          "members": [
            "Alice",
            "Bob",
            "Charlie"
          ]
        },
        {
          "name": "Backend",
          "members": [
            "David",
            "Eve",
            "Frank"
          ]
        }
      ]
    },
    {
      "name": "Marketing",
      "teams": [
        {
          "name": "Digital",
          "members": [
            "Grace",
            "Henry"
          ]
        }
      ]
    }
  ]
}

Fehlerantwort

Beispiel einer API-Fehlermeldung

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid input parameters",
    "details": [
      {
        "field": "email",
        "message": "Email format is invalid"
      },
      {
        "field": "password",
        "message": "Password must be at least 8 characters"
      }
    ]
  },
  "timestamp": "2024-01-01T12:00:00Z",
  "requestId": "req_123456789"
}

GeoJSON

Geodatenformat

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -74.006,
          40.7128
        ]
      },
      "properties": {
        "name": "New York City",
        "population": 8336817
      }
    }
  ]
}

Package.json

Konfigurationsdatei eines Node.js-Projekts

{
  "name": "my-project",
  "version": "1.0.0",
  "description": "A sample Node.js project",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "jest",
    "build": "webpack --mode production"
  },
  "dependencies": {
    "express": "^4.18.0",
    "lodash": "^4.17.21"
  },
  "devDependencies": {
    "jest": "^29.0.0",
    "webpack": "^5.74.0"
  }
}

Gemischte Datentypen

Beispiel mit verschiedenen JSON-Typen

{
  "string": "Hello World",
  "number": 42,
  "float": 3.14159,
  "boolean": true,
  "nullValue": null,
  "array": [
    1,
    "two",
    true,
    null
  ],
  "object": {
    "nested": "value"
  },
  "emptyArray": [],
  "emptyObject": {}
}

功能特性

Viele Beispiele

10 gängige JSON-Strukturen

Ein-Klick-Kopie

JSON sofort in die Zwischenablage

Syntax-Leitfaden

Regeln und Datentypen von JSON

Datenschutz

Alles lokal, keine Datenübertragung

Häufige Fragen

Ja, alle Beispiele sind gültiges JSON und können direkt kopiert werden.
JSON umfasst Objekte, Arrays, Strings, Zahlen, Booleans und null. Strings stehen in doppelten Anführungszeichen, Paare sind durch Doppelpunkte getrennt.
JSON ist ein Datenformat; JS-Objekte sind Sprachstrukturen. JSON verlangt Schlüssel als Strings in doppelten Anführungszeichen.
Mit unserem JSON-Validator finden Sie Fehlerstellen präzise.
Objekte, Arrays, Strings, Zahlen, Booleans (true/false) und null.
So schreibt es die JSON-Spezifikation vor und gewährleistet Sprachkompatibilität.