Insert empty arrays into fields of type JSON in the data warehouse

I defined a field called "value" of type JSON (among some other fields) in the resource store. If I run upserts using simple values โ€‹โ€‹or non-empty arrays, everything works fine:

POST http://host/api/3/action/datastore_upsert
{
   "resource_id": "...",
   "records": [
                 { "value": [ "1", "2" ] }
              ],
   "method": "insert",
   "force": "True"
}

POST http://host/api/3/action/datastore_upsert
{
   "resource_id": "...",
   "records": [
                 { "value": "23" }
              ],
   "method": "insert",
   "force": "True"
}

However, if I use an empty array

POST http://host/api/3/action/datastore_upsert
{
   "resource_id": "...",
   "records": [
                 { "value": [ ] }
              ],
   "method": "insert",
   "force": "True"
}

I get the following error:

{
    ...
    "success": false,
    "error": {
        "info": {
            "orig": [
                "malformed record literal: \"{}\"\nLINE 2:             VALUES (NULL, NULL, NULL, NULL, '{}', NULL, to_t...\n                                                    ^\nDETAIL:  Missing left parenthesis.\n"
            ]
        },
        "__type": "Validation Error",
        "data": "(DataError) malformed record literal: \"{}\"\nLINE 2:             VALUES (NULL, NULL, NULL, NULL, '{}', NULL, to_t...\n                                                    ^\nDETAIL:  Missing left parenthesis.\n"
    }
}

Given what [ ]is a valid element in JSON, I wonder why this error occurs. Is this a known issue / bug in the CKAN datastore API?

+4
source share
1 answer

! . https://github.com/ckan/ckan/pull/1776 . .

, , , , . , pull.

!

+4

Source: https://habr.com/ru/post/1544488/


All Articles