Zig
Zig
JSON Parsing with Sample Data for a Merchant/Payment Transaction
See more JSON Examples
Demonstrates how to load the following JSON into a JSON object and access the values for this document:
{
"id":"8a829449561d9dcb01571dbee3b275b1",
"paymentType":"DB",
"paymentBrand":"VISA",
"amount":"156.00",
"currency":"EUR",
"merchantTransactionId":"E8A39B31-6FA3-4014-A195-3074DF5BF7A1",
"result":{
"code":"000.100.110",
"description":"Request successfully processed in 'Merchant in Integrator Test Mode'"
},
"resultDetails":{
"ConnectorTxID3":"12311312",
"ConnectorTxID1":"717473"
},
"card":{
"bin":"420000",
"last4Digits":"0000",
"holder":"Andreas",
"expiryMonth":"12",
"expiryYear":"2018"
},
"risk":{
"score":"100"
},
"buildNumber":"4b471ea5366e5e9c9a21392a39769f8d7b40b4e8@2016-09-08 13:31:54 +0000",
"timestamp":"2016-09-12 09:33:52+0000",
}
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const json = try chilkat.JsonObject.init();
defer json.deinit();
// Load the JSON into the object.
// Call json.Load to load from a string rather than a file...
try json.loadFile("qa_data/json/merchantPayment.json");
// We are assuming success..
// Get the easy stuff:
std.debug.print("id: {s}\n", .{try json.stringOf(alloc, "id")});
std.debug.print("paymentType: {s}\n", .{try json.stringOf(alloc, "paymentType")});
std.debug.print("currency: {s}\n", .{try json.stringOf(alloc, "currency")});
std.debug.print("buildNumber: {s}\n", .{try json.stringOf(alloc, "buildNumber")});
// Get information that's nested within a sub-object:
std.debug.print("result: code: {s}\n", .{try json.stringOf(alloc, "result.code")});
std.debug.print("result: description: {s}\n", .{try json.stringOf(alloc, "result.description")});
std.debug.print("card: bin: {s}\n", .{try json.stringOf(alloc, "card.bin")});
std.debug.print("card: last4Digits: {s}\n", .{try json.stringOf(alloc, "card.last4Digits")});
}