DPaste 使用文档

Paste as JSON...

The paste as JSON feature provides multiple JSON data processing methods, allowing you to quickly format, compress, escape JSON content, or extract key names from JSON. Whether you need to beautify JSON, compress JSON for transmission, or quickly obtain JSON structure, you can accomplish it easily.

Feature Overview

JSON paste features include the following core operations:

  • JSON Formatting: Format compressed JSON into readable multi-line format
  • JSON Compression: Compress formatted JSON into a single line, saving space
  • JSON Compression and Escape: Compress JSON and escape special characters, suitable for embedding in code or strings
  • Extract JSON Keys: Quickly extract all key names from JSON objects

Usage

Basic Operations

Use via Right-click Menu:
  1. Open DPaste clipboard history (⌘ + Shift + V)
  2. Find a record containing JSON content
  3. Right-click the record
  4. Select "Paste as..." → "JSON Formatting" (or other JSON options)
  5. Content will be pasted in the converted format to the target location
Shortcut Method:
  1. Select a record containing JSON in clipboard history
  2. Use the corresponding shortcut to quickly apply JSON conversion
  3. Content will be pasted in the converted format

Feature Details

1. JSON Formatting

Format compressed JSON into readable multi-line format, convenient for viewing and editing.

Use Cases:
  • JSON responses from APIs are in compressed format, need to view structure
  • Need to view JSON hierarchy when debugging
  • Need to manually edit JSON content
Example:

Input (compressed format):

{"name":"DPaste","version":"1.0","features":["clipboard","ocr"],"settings":{"theme":"dark","language":"zh-CN"}}

Output (after formatting):

{
  "name": "DPaste",
  "version": "1.0",
  "features": [
    "clipboard",
    "ocr"
  ],
  "settings": {
    "theme": "dark",
    "language": "zh-CN"
  }
}
Steps:
  1. Copy compressed JSON content
  2. Find the record in clipboard history
  3. Right-click and select "Paste as..." → "JSON Formatting"
  4. After pasting, you'll get formatted JSON

2. JSON Compression

Compress formatted JSON into a single line, removing all whitespace characters and line breaks, saving space.

Use Cases:
  • Need to use JSON for URL parameters or configuration files
  • Reduce JSON file size
  • Need single-line format JSON for logging
Example:

Input (formatted format):

{
  "name": "DPaste",
  "version": "1.0",
  "features": [
    "clipboard",
    "ocr"
  ]
}

Output (after compression):

{"name":"DPaste","version":"1.0","features":["clipboard","ocr"]}
Steps:
  1. Copy formatted JSON content
  2. Find the record in clipboard history
  3. Right-click and select "Paste as..." → "JSON Compression"
  4. After pasting, you'll get compressed JSON

3. JSON Compression and Escape

Compress JSON and escape special characters, making it suitable for embedding in code strings or using as string values.

Use Cases:
  • Need to embed JSON as a string in code
  • Need JSON string literals in JavaScript/TypeScript
  • Need to escape special characters like quotes, line breaks, etc. in JSON
Example:

Input (formatted format):

{
  "name": "DPaste",
  "description": "A powerful clipboard tool"
}

Output (compressed and escaped):

{\"name\":\"DPaste\",\"description\":\"A powerful clipboard tool\"}
Usage in Code:
const jsonString = "{\"name\":\"DPaste\",\"description\":\"A powerful clipboard tool\"}";
const data = JSON.parse(jsonString);
Steps:
  1. Copy JSON content
  2. Find the record in clipboard history
  3. Right-click and select "Paste as..." → "JSON Compression and Escape"
  4. After pasting, you'll get compressed and escaped JSON string

4. Extract JSON Keys

Quickly extract all key names from JSON objects, convenient for viewing data structure or generating type definitions.

Use Cases:
  • Need to quickly understand what fields a JSON object contains
  • Generate TypeScript interfaces or type definitions
  • Analyze API response data structure
  • Extract field names for code generation
Example:

Input:

{
  "name": "DPaste",
  "version": "1.0",
  "features": ["clipboard", "ocr"],
  "settings": {
    "theme": "dark",
    "language": "zh-CN"
  }
}

Output (extracted keys):

name, version, features, settings
Nested Object Processing:

For nested objects, you can extract key names from all levels:

Input:

{
  "user": {
    "name": "John",
    "email": "john@example.com",
    "profile": {
      "age": 30,
      "city": "Beijing"
    }
  }
}

Output:

user, name, email, profile, age, city
Steps:
  1. Copy JSON content
  2. Find the record in clipboard history
  3. Right-click and select "Paste as..." → "JSON Keys"
  4. After pasting, you'll get a list of all key names

Practical Use Cases

Scenario One: API Debugging

API responses are usually in compressed format, using JSON formatting can quickly view structure:

1. Copy API response: {"status":200,"data":{"users":[{"id":1,"name":"Alice"}]}}
2. Right-click and select "JSON Formatting"
3. Get readable format:
{
  "status": 200,
  "data": {
    "users": [
      {
        "id": 1,
        "name": "Alice"
      }
    ]
  }
}

Scenario Two: Configuration File Processing

Need to compress formatted configuration files for deployment:

1. Copy formatted configuration file
2. Right-click and select "JSON Compression"
3. Get single-line format, easy to store or transmit

Scenario Three: Code Generation

Extract JSON Keys for generating TypeScript interfaces:

1. Copy API response JSON
2. Right-click and select "JSON Keys"
3. Get: status, data, users, id, name
4. Use these key names to quickly generate interface definitions

Scenario Four: String Embedding

Need to embed JSON as a string in code:

1. Copy JSON object
2. Right-click and select "JSON Compression and Escape"
3. Directly paste to string position in code

Notes

JSON Format Requirements

  • All JSON operations require input content to be valid JSON format
  • If content is not valid JSON, conversion may fail
  • Recommend verifying JSON validity before conversion

Data Integrity

  • JSON Compression: Only removes whitespace characters, does not change data content
  • JSON Compression and Escape: Escapes special characters, but data content remains unchanged
  • Extract JSON Keys: Only extracts key names, does not include values, data content will be lost

Performance Considerations

  • For large JSON files (exceeding several MB), formatting operations may take some time
  • Deeply nested JSON may produce long lists when extracting keys

Special Character Processing

  • Compression and Escape feature will escape all special characters, including quotes, backslashes, line breaks, etc.
  • Escaped JSON can be directly used as a string without manually adding escape characters