[keycloak-user] export/import realms - illegal json format?

Ori Doolman Ori.Doolman at cyberark.com
Tue Nov 12 06:28:04 EST 2019


Hi,

I'm using Keycloak docker 7.01 to export all my realms into a json file realms.json.
Then, I take the json file and try to import in another container.
The json looks like:

[ {
    "id" : "tenant1",
    "realm" : "tenant1",
    ....
},
{
    "id" : "tenant2",
    "realm" : "tenant2",
   ....
} ]


However, after I run the import, I get an error about the json format. I checked the json with an online validator, and it seems to be valid.
Is that a bug? Is there any way to reformat the json so it will work?


When I export/import a single tenant, I don't get the error.

Here is my export command:

docker exec keycloak /opt/jboss/keycloak/bin/standalone.sh \
-Djboss.socket.binding.port-offset=100 -Dkeycloak.migration.action=export \
-Dkeycloak.migration.provider=singleFile \
-Dkeycloak.migration.usersExportStrategy=REALM_FILE \
-Dkeycloak.migration.file=/tmp/vol/realms.json


Here is my import command:

sudo docker run -d -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin -e KEYCLOAK_IMPORT=/tmp/vol/realms.json -v /home/caadmin/keycloak:/tmp/vol  --name keycloak jboss/keycloak


This is the error I get:


        ... 8 more
Caused by: java.lang.RuntimeException: Failed to parse json
        at org.keycloak.keycloak-services at 7.0.1//org.keycloak.services.resources.KeycloakApplication.loadJson(KeycloakApplication.java:476)
        at org.keycloak.keycloak-services at 7.0.1//org.keycloak.services.resources.KeycloakApplication.importRealms(KeycloakApplication.java:368)
        at org.keycloak.keycloak-services at 7.0.1//org.keycloak.services.resources.KeycloakApplication.migrateAndBootstrap(KeycloakApplication.java:233)
        at org.keycloak.keycloak-services at 7.0.1//org.keycloak.services.resources.KeycloakApplication$1.run(KeycloakApplication.java:146)
        at org.keycloak.keycloak-server-spi-private at 7.0.1//org.keycloak.models.utils.KeycloakModelUtils.runJobInTransaction(KeycloakModelUtils.java:227)
        at org.keycloak.keycloak-services at 7.0.1//org.keycloak.services.resources.KeycloakApplication.<init>(KeycloakApplication.java:137)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
        at org.jboss.resteasy.resteasy-jaxrs at 3.7.0.Final//org.jboss.resteasy.core.ConstructorInjectorImpl.construct(ConstructorInjectorImpl.java:152)
        ... 31 more
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `org.keycloak.representations.idm.RealmRepresentation` out of START_ARRAY token
 at [Source: (FileInputStream); line: 1, column: 1]


----------------------------------------------------------------------
_______________________________________________ 
This e-mail may contain information that is confidential, privileged or otherwise protected from disclosure.
If you are not an intended recipient of this e-mail, do not duplicate or redistribute it by any means. Please delete it and any attachments and notify the sender that you have received it in error.


More information about the keycloak-user mailing list