Forum

Thread tagged as: Question, Problem

How to make a custom JSON

Good morning, In the collection_items table we find the itemJSON column which puts together all the information for each item.

Each item created has been tagged with categories and these are contained in the JSON as category IDs.

My question is if there is a way to extract this information from the database with a query, because I don't seem to find the related fields for each item anywhere.

In a different approach, i tried decoding the existing JSON and re-encoding it while customising its contents. Again I found that the category IDs were the problem and before I go further into this solution I though to ask this question.

Spyros Perris

Spyros Perris 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you take a step back and explain what you're trying to achieve by doing this?

Of course, sorry I didn't mention this, I want to submit our content to swiftype.com one of the search-as-a-service providers.

Drew McLellan

Drew McLellan 2638 points
Perch Support

How about listening for the region.index event?

https://docs.grabaperch.com/api/events/

I tried to listen to region.index and also to item.log_resources after creating in my app an "admin.php" file. Then to listen to the event I am doing a "save" while on a collection item page. Does this event also fire elsewhere where I should check?

As far as I can see, the data returned in the PerchSystemEvent Object and specifically the details of the "item" in the collection are the same ones (i.e. itemJSON, itemSearch). This means that I should hook somewhere before this? Can this be done?

Also, I would need to "collect" all the items in one go and put them into a single JSON. Because one by one wouldn't make sense for creating a total index.

I hope what I'm saying makes sense,

Have a nice evening :)

Drew McLellan

Drew McLellan 2638 points
Perch Support

My thinking was that you can then index the items as they are created or as they change.

If that's not going to work, how about using the existing index tables?

index the items as they are created or as they change

I don't think I know how to do this... It would be an sql statement? Should I look into sql documentation for this?

By the existing index tables you mean the table "collection_index"? In this case the data is again already formatted in way that I can't pick the needed.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What output format are you trying to get?

For each item in the collection I need to get the categories with which it has been tagged. The thing is that from the tables I can't figure out how. However in the "itemJSON" of each item the info is there, only that I need to replace the category IDs with their names. The structure is perfect.