Bỏ qua, đến nội dung

@digiforce-nc/plugin-workflow-get-json-field

Plugin đăng ký node trích xuất field từ JSON trong workflow, mở rộng plugin-workflow. Sử dụng dot path hoặc array index để lấy giá trị cụ thể từ object JSON phức tạp.

Plugin này làm gì?

Node Get JSON Field nhận một object JSON (từ biến workflow, HTTP response, hoặc dữ liệu bản ghi) và trích xuất giá trị tại đường dẫn (path) chỉ định. Hỗ trợ dot notation, array index, và nested path.

Khi workflow nhận dữ liệu từ API bên ngoài (qua HTTP Request node hoặc Webhook trigger), dữ liệu thường là JSON phức tạp nhiều cấp. Node này giúp "đào" vào đúng field cần thiết mà không cần viết JavaScript.

Cấu hình

Tham sốKiểuMô tả
sourcestringBiến workflow chứa JSON object nguồn
pathstringĐường dẫn trích xuất (dot notation): data.user.name
defaultValueanyGiá trị mặc định khi path không tồn tại
parseJsonbooleanTự động parse string thành JSON trước khi trích xuất

Input / Output

HướngDữ liệuMô tả
InputsourceObject JSON hoặc chuỗi JSON
InputpathĐường dẫn field cần lấy
OutputresultGiá trị tại path (bất kỳ kiểu: string, number, object, array)
Outputexiststrue nếu path tồn tại, false nếu dùng defaultValue

Tính năng chính

#Tính năngChi tiết
1Dot notationTruy cập nested field: user.address.city
2Array indexTruy cập phần tử mảng: items[0], items[-1] (cuối)
3Auto parseTự động parse chuỗi JSON thành object
4Default valueGiá trị fallback khi path không tìm thấy
5Nested pathKết hợp object và array: data.users[2].roles[0].name

Trường hợp sử dụng

#Kịch bảnMô tả
1Lấy token từ APITrích data.access_token từ response đăng nhập
2Đọc webhook dataLấy payload.order.id từ body webhook Shopee
3Parse configĐọc settings.smtp.host từ JSON config lưu trong DB
4Lấy phần tử đầuTrích results[0] từ kết quả search API
5Nested extractionLấy data.customer.addresses[0].city từ response CRM

Ví dụ path thường dùng

PathMô tảKết quả
data.nameField đơn giản"John"
items[0]Phần tử đầu tiênobject
items[-1]Phần tử cuối cùngobject
data.users[0].emailNested + array"john@example.com"
meta.totalMetadata field42

Lưu ý quan trọng

  • Path phân biệt hoa thường: user.Name khác user.name
  • Nếu source là string, bật parseJson: true để tự động parse
  • Array index âm: items[-1] lấy phần tử cuối, items[-2] lấy phần tử kế cuối
  • Khi path trỏ đến object hoặc array, kết quả là toàn bộ object/array đó
  • Nếu source là null hoặc undefined, trả về defaultValue ngay

Dependencies

PackageVai trò
@digiforce-nc/plugin-workflowWorkflow engine (peer)
@digiforce-nc/serverServer framework (peer)

Mục lục chi tiết