Skip to content

feature: handle nested objects when getting attribute values#2235

Open
johnnyblasta wants to merge 4 commits intomasterfrom
nested-attribute
Open

feature: handle nested objects when getting attribute values#2235
johnnyblasta wants to merge 4 commits intomasterfrom
nested-attribute

Conversation

@johnnyblasta
Copy link
Collaborator

Closes #2234

@Grammostola
Copy link
Contributor

Grammostola commented Oct 29, 2025

I was going to test this but I'm not clever enough : /

In the issue you wrote

If an attribute is defined like this {"name": "detaljplan.beteckning"} and the attribute is a JSON object like below it should be possible to get the attribute value by drilling down in the object.

{
    "detaljplan": {
        "objektidentitet": "0490dfc9-8dxf-4992-bcbb-9ed8ab6137d9",
        "beteckning": "2281K-DP-xx",
        "namn": "xxxx",
        "status": "laga kraft",
        "typ": "detaljplan",
        "datumLagakraft": "1991-12-05",
        "kvalitet": {
            "korrigeradeGranser": true,
            "kontrolleratPlaneringsunderlag": false
        },
        "anvandbarhet": "god"
    }
}

So if an attribute of a geojson feature has a prop like {"name": "detaljplan.beteckning"} where (in the geojson) would the detaljplan object be defined?
Edit. In a detaljplan prop of the same feature?

@johnnyblasta
Copy link
Collaborator Author

Below is a complete GeoJSON from the OGC API Features from Lantmäteriet's service for NGD Detaljplan, which you can use for testing purpose.
When consumed as a GeoJSON in Origo the properties are json objects that have to be drilled down to get the value of the nested query.

{
    "type": "FeatureCollection",
    "bbox": [
        614465.2668658032,
        6922102.783130676,
        615040.9961061939,
        6922533.367391475
    ],
    "features": [
        {
            "stac_version": "0.9.0",
            "id": "000b2be4-4912-4272-a443-60f082a093a2",
            "type": "Feature",
            "geometry": {
                "type": "MultiPolygon",
                "coordinates": [
                    [
                        [
                            [
                                614698.0911554318,
                                6922174.210286537
                            ],
                            [
                                614794.4010474744,
                                6922153.904904148
                            ],
                            [
                                614795.8682177276,
                                6922153.602365562
                            ],
                            [
                                614809.4432434513,
                                6922150.803187086
                            ],
                            [
                                614864.2533038133,
                                6922139.501183849
                            ],
                            [
                                614907.8644717804,
                                6922130.508390622
                            ],
                            [
                                614898.2618863684,
                                6922138.335299951
                            ],
                            [
                                614890.349171114,
                                6922150.010247786
                            ],
                            [
                                614886.558512968,
                                6922153.927633894
                            ],
                            [
                                614875.3881140824,
                                6922162.723722304
                            ],
                            [
                                614862.5382988811,
                                6922168.695911597
                            ],
                            [
                                614715.6134266328,
                                6922236.25671467
                            ],
                            [
                                614709.3397552317,
                                6922239.183099282
                            ],
                            [
                                614702.5034260511,
                                6922213.312128946
                            ],
                            [
                                614700.9399809355,
                                6922207.3935327465
                            ],
                            [
                                614692.4829373533,
                                6922175.392696744
                            ],
                            [
                                614698.0911554318,
                                6922174.210286537
                            ]
                        ]
                    ],
                    [
                        [
                            [
                                615024.5659806476,
                                6922127.110136032
                            ],
                            [
                                615038.1484272364,
                                6922126.03144576
                            ],
                            [
                                615040.9961061939,
                                6922140.629745211
                            ],
                            [
                                615029.7632349576,
                                6922143.512187668
                            ],
                            [
                                614996.4947855817,
                                6922152.2312143305
                            ],
                            [
                                614927.0125976785,
                                6922217.431394903
                            ],
                            [
                                614941.2965403609,
                                6922237.201593471
                            ],
                            [
                                614960.3863258243,
                                6922262.907470189
                            ],
                            [
                                614961.5297633026,
                                6922271.0309611345
                            ],
                            [
                                614954.2404276159,
                                6922280.9002445135
                            ],
                            [
                                614919.7618707109,
                                6922314.897924522
                            ],
                            [
                                614877.6541777975,
                                6922320.4110536175
                            ],
                            [
                                614863.6289674308,
                                6922314.342696502
                            ],
                            [
                                614848.4112415004,
                                6922312.321314533
                            ],
                            [
                                614828.5119066829,
                                6922324.4102463955
                            ],
                            [
                                614818.1555523732,
                                6922330.4701604135
                            ],
                            [
                                614786.2189912912,
                                6922350.111538774
                            ],
                            [
                                614758.5753367173,
                                6922373.773829528
                            ],
                            [
                                614751.7053464297,
                                6922402.602963922
                            ],
                            [
                                614684.4163345856,
                                6922442.343653644
                            ],
                            [
                                614632.4560052523,
                                6922497.612333247
                            ],
                            [
                                614614.3312659282,
                                6922511.116341872
                            ],
                            [
                                614583.63196206,
                                6922528.278753664
                            ],
                            [
                                614574.8322932777,
                                6922533.367391475
                            ],
                            [
                                614551.4003542699,
                                6922511.1719579315
                            ],
                            [
                                614539.0800835973,
                                6922499.068237047
                            ],
                            [
                                614541.0898263667,
                                6922495.505992884
                            ],
                            [
                                614544.4833219819,
                                6922489.224922152
                            ],
                            [
                                614538.7207036968,
                                6922485.269468604
                            ],
                            [
                                614537.9730538045,
                                6922483.634242622
                            ],
                            [
                                614537.755552379,
                                6922482.178437515
                            ],
                            [
                                614538.3503851609,
                                6922480.658387171
                            ],
                            [
                                614571.2973747568,
                                6922459.641805016
                            ],
                            [
                                614566.1047801444,
                                6922452.977001506
                            ],
                            [
                                614565.1839038129,
                                6922451.791710232
                            ],
                            [
                                614557.8269443234,
                                6922442.31663283
                            ],
                            [
                                614554.7101151617,
                                6922439.647554215
                            ],
                            [
                                614547.7123972123,
                                6922433.642354885
                            ],
                            [
                                614550.9369881225,
                                6922431.082567885
                            ],
                            [
                                614585.4054533435,
                                6922403.7197174
                            ],
                            [
                                614580.3773346196,
                                6922389.890012947
                            ],
                            [
                                614578.1619340281,
                                6922383.7967587
                            ],
                            [
                                614563.408774025,
                                6922343.218911652
                            ],
                            [
                                614589.734851184,
                                6922317.045245568
                            ],
                            [
                                614618.4610740711,
                                6922293.509693699
                            ],
                            [
                                614633.3027988416,
                                6922283.757466437
                            ],
                            [
                                614651.0794440813,
                                6922273.010039529
                            ],
                            [
                                614685.0627647782,
                                6922256.085507997
                            ],
                            [
                                614754.5161249521,
                                6922224.561441756
                            ],
                            [
                                614838.6830814781,
                                6922186.965016953
                            ],
                            [
                                614873.6841564677,
                                6922170.075908876
                            ],
                            [
                                614879.9084349982,
                                6922166.921918555
                            ],
                            [
                                614895.0912982943,
                                6922154.124434291
                            ],
                            [
                                614901.5335947738,
                                6922144.706830531
                            ],
                            [
                                614905.3470800729,
                                6922140.998615663
                            ],
                            [
                                614924.4714825356,
                                6922127.083924157
                            ],
                            [
                                614938.1808340835,
                                6922125.871302663
                            ],
                            [
                                614952.24441099,
                                6922122.6737818485
                            ],
                            [
                                614982.2853575507,
                                6922105.736181382
                            ],
                            [
                                615003.5231784326,
                                6922103.954816046
                            ],
                            [
                                615015.1705494069,
                                6922102.783130676
                            ],
                            [
                                615015.9056195768,
                                6922104.549868448
                            ],
                            [
                                615018.3858212035,
                                6922110.511097435
                            ],
                            [
                                615021.4153220861,
                                6922118.313825135
                            ],
                            [
                                615024.2573102174,
                                6922126.186751468
                            ],
                            [
                                615024.5659806476,
                                6922127.110136032
                            ]
                        ]
                    ],
                    [
                        [
                            [
                                614473.4700542255,
                                6922352.464861188
                            ],
                            [
                                614465.2668658032,
                                6922346.733401868
                            ],
                            [
                                614474.9017160507,
                                6922331.185902811
                            ],
                            [
                                614520.3718951086,
                                6922269.138314791
                            ],
                            [
                                614538.8891243957,
                                6922248.218142328
                            ],
                            [
                                614554.7363518778,
                                6922233.164674265
                            ],
                            [
                                614570.5441404913,
                                6922218.7984839305
                            ],
                            [
                                614589.9004622083,
                                6922206.970848918
                            ],
                            [
                                614592.8085445923,
                                6922212.959976501
                            ],
                            [
                                614600.4025875397,
                                6922209.226659232
                            ],
                            [
                                614608.0531711781,
                                6922205.610552987
                            ],
                            [
                                614615.7585586808,
                                6922202.112697694
                            ],
                            [
                                614623.5168273016,
                                6922198.733726655
                            ],
                            [
                                614631.326140296,
                                6922195.474676323
                            ],
                            [
                                614639.1847782317,
                                6922192.336087039
                            ],
                            [
                                614643.4560410136,
                                6922190.687266352
                            ],
                            [
                                614647.740866601,
                                6922189.0741308415
                            ],
                            [
                                614652.0389587268,
                                6922187.496570153
                            ],
                            [
                                614656.3501036448,
                                6922185.954976994
                            ],
                            [
                                614665.0100531236,
                                6922182.979641063
                            ],
                            [
                                614684.7673775938,
                                6922177.522197234
                            ],
                            [
                                614692.9200396915,
                                6922210.223093859
                            ],
                            [
                                614694.381509581,
                                6922216.085319458
                            ],
                            [
                                614695.0575647539,
                                6922218.796948307
                            ],
                            [
                                614681.0115588135,
                                6922223.776828252
                            ],
                            [
                                614689.9811622605,
                                6922247.232071124
                            ],
                            [
                                614665.5791219159,
                                6922257.378046387
                            ],
                            [
                                614647.9378637632,
                                6922266.48408531
                            ],
                            [
                                614629.2052566197,
                                6922277.668495126
                            ],
                            [
                                614620.5007950427,
                                6922284.211587456
                            ],
                            [
                                614583.3550275427,
                                6922314.648980773
                            ],
                            [
                                614504.017753832,
                                6922390.788895163
                            ],
                            [
                                614471.8359033252,
                                6922370.23668577
                            ],
                            [
                                614467.8089788526,
                                6922367.667063669
                            ],
                            [
                                614472.7379075044,
                                6922353.584584774
                            ],
                            [
                                614473.4700542255,
                                6922352.464861188
                            ]
                        ]
                    ]
                ]
            },
            "bbox": [
                614465.2668658032,
                6922102.783130676,
                615040.9961061939,
                6922533.367391475
            ],
            "properties": {
                "datetime": "2024-10-02T13:41:55.102124+02:00",
                "providers": [
                    {
                        "name": "Sundsvalls kommun",
                        "roles": [
                            "producer"
                        ],
                        "kod": "2281"
                    }
                ],
                "title": "BERGSÅKER,DEL AV(CENTRUM MM)",
                "feature": {
                    "typ": "detaljplan",
                    "etikett": "BERGSÅKER,DEL AV(CENTRUM MM)"
                },
                "detaljplan": {
                    "objektidentitet": "000b2be4-4912-4272-a443-60f082a093a2",
                    "beteckning": "2281K-SEL-123",
                    "namn": "BERGSÅKER,DEL AV(CENTRUM MM)",
                    "status": "laga kraft",
                    "datumStatusforandring": "1971-01-28",
                    "typ": "stadsplan",
                    "datumLagakraft": "1971-01-28",
                    "kvalitet": {
                        "korrigeradeGranser": true,
                        "kontrolleratPlaneringsunderlag": false
                    },
                    "anvandbarhet": "god"
                }
            },
            "links": [
                {
                    "href": "https://api.lantmateriet.se/distribution/geodatakatalog/sokning/v1/detaljplan/v2/collections/2281/items/000b2be4-4912-4272-a443-60f082a093a2",
                    "rel": "self",
                    "type": "application/geo+json"
                },
                {
                    "href": "https://api.lantmateriet.se/distribution/geodatakatalog/sokning/v1/detaljplan/v2/",
                    "rel": "root",
                    "type": "application/json"
                },
                {
                    "href": "https://api.lantmateriet.se/distribution/geodatakatalog/sokning/v1/detaljplan/v2/collections/2281",
                    "rel": "parent",
                    "type": "application/json"
                },
                {
                    "href": "https://api.lantmateriet.se/distribution/geodatakatalog/sokning/v1/detaljplan/v2/collections/2281",
                    "rel": "collection",
                    "type": "application/json"
                }
            ],
            "assets": {
                "asset-1": {
                    "href": "https://api.lantmateriet.se/distribution/geodatakatalog/nedladdning/v1/asset/000b2be4-4912-4272-a443-60f082a093a2",
                    "type": "application/vnd.lm.detaljplan.v4+json",
                    "title": "Detaljplan",
                    "length": 386312,
                    "roles": [
                        "detaljplan"
                    ]
                },
                "asset-2": {
                    "href": "https://api.lantmateriet.se/distribution/geodatakatalog/nedladdning/v1/asset/140c90de-bd74-493e-8eaf-15a9afb37642",
                    "title": "Plankarta",
                    "roles": [
                        "beslutshandling"
                    ]
                },
                "asset-3": {
                    "href": "https://api.lantmateriet.se/distribution/geodatakatalog/nedladdning/v1/asset/4b3c0d59-69ca-4f08-aecd-20d5738aa994",
                    "title": "Upphävande av fastighetsindelningsbestämmelser 2014",
                    "roles": [
                        "beslutshandling"
                    ]
                },
                "asset-4": {
                    "href": "https://api.lantmateriet.se/distribution/geodatakatalog/nedladdning/v1/asset/742d7aca-89c4-4a73-8959-344f480aa982",
                    "title": "Planhandling",
                    "roles": [
                        "planbeskrivning"
                    ]
                },
                "asset-5": {
                    "href": "https://api.lantmateriet.se/distribution/geodatakatalog/nedladdning/v1/asset/b494227a-89a7-425c-82fe-c555f0604c29",
                    "title": "Viktig info.ang detaljplanens höjdsystem och rättsverkan",
                    "roles": [
                        "planeringsunderlag"
                    ]
                }
            },
            "collection": "2281"
        }
    ],
    "links": [
        {
            "href": "https://api.lantmateriet.se/distribution/geodatakatalog/sokning/v1/detaljplan/v2/search?afterId=000b2be4-4912-4272-a443-60f082a093a2",
            "rel": "next",
            "type": "application/geo+json",
            "method": "POST",
            "merge": true
        },
        {
            "href": "https://api.lantmateriet.se/distribution/geodatakatalog/sokning/v1/detaljplan/v2/",
            "rel": "root",
            "type": "application/json"
        },
        {
            "href": "https://api.lantmateriet.se/distribution/geodatakatalog/sokning/v1/detaljplan/v2/search",
            "rel": "self",
            "type": "application/geo+json",
            "method": "POST",
            "merge": true
        }
    ]
}

@Grammostola
Copy link
Contributor

Grammostola commented Oct 30, 2025

Seems to function as intended, i.e I can specify attributes for the above feature that can be name: detaljplan.kvalitet.korrigeradeGranser . The only thing giving me a slight pause is the jsdocs for getContent. I don't know if the constant declaration ought to be used for an object with methods and the kind: variable with it seems counterintuitive.

Maybe each method inside should be documented and the parameters described via typeDef

@johnnyblasta
Copy link
Collaborator Author

I let Visual Studio Code do the DocTypes thing for the JSDoc so I don't rely know if it's good or not :)

@Grammostola
Copy link
Contributor

To sum what we discussed during our meeting then, merge with proposed similar function "searchjson" https://github.com/origo-map/origo/pull/2224/files#diff-73a377a3fa3092fb30d691c5c3145af68f00519db030398cef9a51111b1566d5 , as for jsdocs for getContent I'm thinking this pr doesn't necessarily need to include them?

@johnnyblasta
Copy link
Collaborator Author

To sum what we discussed during our meeting then, merge with proposed similar function "searchjson" https://github.com/origo-map/origo/pull/2224/files#diff-73a377a3fa3092fb30d691c5c3145af68f00519db030398cef9a51111b1566d5 , as for jsdocs for getContent I'm thinking this pr doesn't necessarily need to include them?

Tested using the "searchjson" function, but found it quiet different and had difficulty implementing using that function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Attribute should handle nested JSON object

2 participants