Custom json format | Ja_serializer View

i am having issue with has_many records. i am getting data in included.

{ "jsonapi": { "version": "1.0" }, "included": [ { "type": "users-account", "id": "65", "attributes": { "preFix": null, "account-number": 65, "accountId": null, "AccountNumber": "000000039" } }, { "type": "users-account", "id": "205", "attributes": { "preFix": null, "account-number": 203, "accountId": null, "AccountNumber": "1840000207057677110" } } ], "data": { "type": "party", "relationships": { “users-account": { "data": [ { "type": "users-account", "id": "65" }, { "type": "users-account", "id": "205" } ] } }, "id": "60", "attributes": { "partyType": "user", "idString": "Yy8KxRP" } } }

I want data like this

{
    "jsonapi": {
        "version": "1.0"
    },
    "data": {
        "type": "party",
        "relationships": {
            "users-account": {
                "data": [
                    {
                        "type": "users-account",
                        "id": "65",
                        "attributes": {
                "preFix": null,
                "account-number": 65,
                "accountId": null,
                "AccountNumber": "000000039"
            }
                    },
                    {
                        "type": "users-account",
                        "id": "205",
                         "attributes": {
                "preFix": null,
                "account-number": 203,
                "accountId": null,
                "AccountNumber": "057677110"
            }
                    }
                ]
            }
        },
        "id": "60",
        "attributes": {
            "partyType": "user",
            "idString": "OTsRiYy8KxRP"
        }
    }
}

i am using Ja_serializer. is there any way i can customise views with relations.

1 Like