schema compile CHANGE order keys at the beginning of the children list
diff --git a/src/tree_data_hash.c b/src/tree_data_hash.c
index 37d6337..33104cc 100644
--- a/src/tree_data_hash.c
+++ b/src/tree_data_hash.c
@@ -51,10 +51,16 @@
 
     if (node->schema->nodetype == LYS_LIST) {
         struct lyd_node_inner *list = (struct lyd_node_inner*)node;
-        if (((struct lysc_node_list*)node->schema)->keys) {
+        if (!(node->schema->flags & LYS_KEYLESS)) {
             /* list's hash is made of its keys */
-            unsigned int keys_count = LY_ARRAY_SIZE(((struct lysc_node_list*)node->schema)->keys);
-            for (iter = list->child; iter && keys_count; --keys_count, iter = iter->next) {
+            struct lysc_node *key;
+            for (key = ((struct lysc_node_list*)node->schema)->child, iter = list->child;
+                    key && key->nodetype == LYS_LEAF && (key->flags & LYS_KEY) && iter;
+                    key = key->next, iter = iter->next) {
+                for ( ; iter && iter->schema != key; iter = iter->next);
+                if (!iter) {
+                    break;
+                }
                 int dynamic = 0;
                 struct lysc_type *type = ((struct lysc_node_leaf*)iter->schema)->type;
                 const char *value = type->plugin->print(&((struct lyd_node_term*)iter)->value, LYD_JSON, json_print_get_prefix, NULL, &dynamic);