| 383 | }; |
| 384 | |
| 385 | void working_with_cbor1() |
| 386 | { |
| 387 | // Parse the CBOR data into a json value |
| 388 | json j = cbor::decode_cbor<json>(data); |
| 389 | |
| 390 | // Pretty print |
| 391 | std::cout << "(1)\n" << pretty_print(j) << "\n\n"; |
| 392 | |
| 393 | // Iterate over rows |
| 394 | std::cout << "(2)\n"; |
| 395 | for (const auto& row : j.array_range()) |
| 396 | { |
| 397 | std::cout << row[1].as<jsoncons::byte_string>() << " (" << row[1].tag() << ")\n"; |
| 398 | } |
| 399 | std::cout << "\n"; |
| 400 | |
| 401 | // Select the third column with JSONPath |
| 402 | std::cout << "(3)\n"; |
| 403 | json result = jsonpath::json_query(j,"$[*][2]"); |
| 404 | std::cout << pretty_print(result) << "\n\n"; |
| 405 | |
| 406 | // Serialize back to CBOR |
| 407 | std::vector<uint8_t> buffer; |
| 408 | cbor::encode_cbor(j, buffer); |
| 409 | std::cout << "(4)\n" << byte_string_view(buffer) << "\n\n"; |
| 410 | } |
| 411 | |
| 412 | void working_with_cbor2() |
| 413 | { |
no test coverage detected