parse json help

12 views
Skip to first unread message

William Flow

unread,
Nov 18, 2022, 3:52:39 PM11/18/22
to Ansible Project
Why this is marked as abuse? It has been marked as abuse.
Report not abuse
So I have a little PB that makes and API call to get some data:

- name: API Commmand to get Snipe-IT List User asests checked out
       ansible.builtin.uri:
        headers:
          Authorization: '{{ snipe }}'
          Content-Type: "application/json"
        method: GET
        return_content: yes
        status_code:
          - 200
       register: asset_content

     - debug:
        msg: '{{asset_content.json }}'
=================================================================
it gives me (TMI):
{
  "msg": {
    "total": 2,
    "rows": [
      {
        "id": 54,
        "name": "",
        "asset_tag": "10.246.76.194",
        "serial": "",
        "model": {
          "id": 51,
          "name": "Openstack Director"
        },
        "model_number": null,
        "eol": null,
        "status_label": {
          "id": 2,
          "name": "Ready to Deploy",
          "status_type": "deployable",
          "status_meta": "deployable"
        },
        "category": {
          "id": 2,
          "name": "R640 Compute"
        },
        "manufacturer": {
          "id": 1,
          "name": "Dell Compute"
        },
        "supplier": null,
        "notes": null,
        "order_number": null,
        "company": null,
        "location": null,
        "rtd_location": {
          "id": 1,
          "name": "COS - ARV"
        },
        "image": null,
        "qr": null,
        "alt_barcode": "http://snipeit.devops.XXXXXXXXXXXXXX.com/uploads/barcodes/c128-1024676194.png",
        "assigned_to": null,
        "warranty_months": null,
        "warranty_expires": null,
        "created_at": {
          "datetime": "2022-11-11 21:20:54",
          "formatted": "2022-11-11 09:20 PM"
        },
        "updated_at": {
          "datetime": "2022-11-14 23:36:38",
          "formatted": "2022-11-14 11:36 PM"
        },
        "last_audit_date": null,
        "next_audit_date": null,
        "deleted_at": null,
        "purchase_date": null,
        "last_checkout": {
          "datetime": "2022-11-14 23:36:38",
          "formatted": "2022-11-14 11:36 PM"
        },
        "expected_checkin": null,
        "purchase_cost": null,
        "checkin_counter": 0,
        "checkout_counter": 1,
        "requests_counter": 0,
        "user_can_checkout": false,
        "custom_fields": [],
        "available_actions": {
          "checkout": true,
          "checkin": true,
          "clone": true,
          "restore": false,
          "update": true,
          "delete": false
        }
      },
      {
        "id": 58,
        "name": "",
        "asset_tag": "10.246.76.28",
        "serial": "",
        "model": {
          "id": 53,
          "name": "vCenter Teledyne"
        },
        "model_number": null,
        "eol": null,
        "status_label": {
          "id": 2,
          "name": "Ready to Deploy",
          "status_type": "deployable",
          "status_meta": "deployable"
        },
        "category": {
          "id": 3,
          "name": "Peripherals"
        },
        "manufacturer": {
          "id": 5,
          "name": "Teledyne Q-Flex"
        },
        "supplier": null,
        "notes": null,
        "order_number": null,
        "company": null,
        "location": null,
        "rtd_location": {
          "id": 1,
          "name": "COS - ARV"
        },
        "image": null,
        "qr": null,
        "alt_barcode": "http://snipeit.devops.XXXXXXXXXXXXXX.com/uploads/barcodes/c128-102467628.png",
        "assigned_to": null,
        "warranty_months": null,
        "warranty_expires": null,
        "created_at": {
          "datetime": "2022-11-11 21:20:54",
          "formatted": "2022-11-11 09:20 PM"
        },
        "updated_at": {
          "datetime": "2022-11-14 21:52:55",
          "formatted": "2022-11-14 09:52 PM"
        },
        "last_audit_date": null,
        "next_audit_date": null,
        "deleted_at": null,
        "purchase_date": null,
        "last_checkout": {
          "datetime": "2022-11-11 21:27:13",
          "formatted": "2022-11-11 09:27 PM"
        },
        "expected_checkin": {
          "date": "2022-11-14",
          "formatted": "2022-11-14"
        },
        "purchase_cost": null,
        "checkin_counter": 0,
        "checkout_counter": 1,
        "requests_counter": 0,
        "user_can_checkout": false,
        "custom_fields": [],
        "available_actions": {
          "checkout": true,
          "checkin": true,
          "clone": true,
          "restore": false,
          "update": true,
          "delete": false
        }
      }
    ]
  },
  "_ansible_verbose_always": true,
  "_ansible_no_log": false,
  "changed": false
}
=======================================================================

now the issue I want  to do I just want the 

{
        "id": 54,
        "name": "",
        "asset_tag": "10.246.76.194",
        "serial": "",
        "model": {
          "id": 51,
          "name": "Openstack Director"
        },

and 

 "category": {
          "id": 2,
          "name": "R640 Compute"
        },
and
        "manufacturer": {
          "id": 1,
          "name": "Dell Compute"
        },

and there could me more then 1 set of this data, plus I am at a total loss on how to do it been trying with jq and just get errors at my wits end here i am no json expert any help I would be grateful

Thanks

W
Reply all
Reply to author
Forward
0 new messages