使用PostgreSQL过滤JSON /排除JSON数组的元素

时间:2015-06-18 21:31:05

标签: json postgresql filter postgresql-9.4

我希望能够使用PostgreSQL返回部分JSON。例如,如果我有JSON

{
    "dress_code": "casual",
    "design": "Solid",
    "fit": "Straight-cut",
    "aesthetic": [
        {
            "aesthetic_id": 1,
            "primary_color": "light blue",
            "secondary_color": "light gray",
            "sizes": [
                {
                    "size_id": "1",
                    "basic_size": "S",
                    "waist": 30,
                    "pictures": [
                        {
                            "angle": "front",
                            "url": "fashion.com/img1f"
                        },
                        {
                            "angle": "back",
                            "url": "fashion.com/img1b"
                        }
                    ]
                },
                {
                    "size_id": "2",
                    "basic_size": "M",
                    "waist": 33,
                    "pictures": [
                        {
                            "angle": "front",
                            "url": "fashion.com/img1f"
                        },
                        {
                            "angle": "back",
                            "url": "fashion.com/img1b"
                        }
                    ]
                }
            ]
        },
        {
            "aesthetic_id": 2,
            "primary_color": "dark blue",
            "secondary_color": "light gray",
            "sizes": [
                {
                    "size_id": "3",
                    "basic_size": "S",
                    "waist": 30,
                    "pictures": [
                        {
                            "angle": "front",
                            "url": "fashion.com/img2f"
                        },
                        {
                            "angle": "back",
                            "url": "fashion.com/img2b"
                        }
                    ]
                },
                {
                    "size_id": "4",
                    "basic_size": "M",
                    "waist": 33,
                    "pictures": [
                        {
                            "angle": "front",
                            "url": "fashion.com/img2f"
                        },
                        {
                            "angle": "back",
                            "url": "fashion.com/img2b"
                        }
                    ]
                }
            ]
        }
    ]
}

并且,例如,我只想要americ_id = 2和size_id = 4的数组和信息,这将是:

{
    "dress_code": "casual",
    "design": "Solid",
    "fit": "Straight-cut",
    "aesthetic": [
        {
            "aesthetic_id": 2,
            "primary_color": "dark blue",
            "secondary_color": "light gray",
            "sizes": [
                {
                    "size_id": "4",
                    "basic_size": "M",
                    "waist": 33,
                    "pictures": [
                        {
                            "angle": "front",
                            "url": "fashion.com/img2f"
                        },
                        {
                            "angle": "back",
                            "url": "fashion.com/img2b"
                        }
                    ]
                }
            ]
        }
    ]
}

有没有一种使用PostgreSQL过滤JSON数据的好方法?

0 个答案:

没有答案