Bỏ qua, đến nội dung

Ví dụ sử dụng - Get JSON Field

Ví dụ 1: Trích xuất token từ API response

Gọi API đăng nhập, trích xuất access_token từ response để dùng cho các request tiếp theo.

Cấu hình node Get JSON Field:

  • source: biến kết quả từ HTTP Request node
  • path: data.access_token
  • defaultValue: null

Response từ API login có cấu trúc { "data": { "access_token": "eyJ...", "expires_in": 3600 } }. Node trích xuất đúng field token mà không cần viết JavaScript.

Ví dụ 2: Đọc dữ liệu webhook Shopee

Webhook từ Shopee gửi payload phức tạp nhiều cấp, cần trích xuất thông tin đơn hàng.

Cấu hình node Get JSON Field (order_sn):

  • source: biến webhookBody
  • path: data.order.order_sn
  • defaultValue: "UNKNOWN"

Cấu hình node Get JSON Field (items):

  • source: biến webhookBody
  • path: data.order.items
  • defaultValue: []

Webhook Shopee có cấu trúc nested sâu. Hai node Get JSON Field trích xuất mã đơn hàng và danh sách sản phẩm để xử lý. Default value [] cho items đảm bảo node Loop phía sau không lỗi khi mảng rỗng.

Ví dụ 3: Parse cấu hình từ JSON trong database

Đọc cấu hình SMTP từ field JSON settings lưu trong collection Config.

Cấu hình node Get JSON Field:

  • source: biến configRecord.settings
  • path: smtp.host
  • parseJson: true
  • defaultValue: "localhost"

Field settings trong database lưu dưới dạng JSON string. Bật parseJson: true để tự động parse string thành object trước khi trích xuất path smtp.host.