importing pretty printed JSON Schema (import database) throwing error - Expected content is "name" but found "id"
OSX 10.10.3 and OrientDB 2.0.5
- Export database GratefulDeadConcerts to grateful.json
- Pretty print this json by
python -m json.tool grateful.json > grateful-pretty.json - Reimport this json into a new database (4. You can validate that the original, unpretty JSON export works just fine when importing)
Hit Error:
WARN: Exported database does not support manual index separation. Manual index cluster will be dropped.Error on database import happened just before line 3, column 17
java.text.ParseException: Expected content is "name" but found "id"
at com.orientechnologies.orient.core.serialization.serializer.OJSONReader.checkContent(OJSONReader.java:63)
at com.orientechnologies.orient.core.db.tool.ODatabaseImport.importClusters(ODatabaseImport.java:1016)
at com.orientechnologies.orient.core.db.tool.ODatabaseImport.importDatabase(ODatabaseImport.java:421)
at com.orientechnologies.orient.console.OConsoleDatabaseApp.importDatabase(OConsoleDatabaseApp.java:1539)
at com.orientechnologies.orient.graph.console.OGremlinConsole.importDatabase(OGremlinConsole.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.orientechnologies.common.console.OConsoleApplication.execute(OConsoleApplication.java:381)
at com.orientechnologies.common.console.OConsoleApplication.executeCommands(OConsoleApplication.java:246)
at com.orientechnologies.common.console.OConsoleApplication.run(OConsoleApplication.java:135)
at com.orientechnologies.orient.graph.console.OGremlinConsole.main(OGremlinConsole.java:62)
Error: com.orientechnologies.orient.core.db.tool.ODatabaseExportException: Error on importing database 'imported_grateful_pretty' from file: /Users/sathia/Downloads/grateful-pretty.json
Error: java.text.ParseException: Expected content is "name" but found "id"
I think this might be related to python's behavior of alphabetic ordering of json keys and how OrientDB expects them to be ordered...
I can confirm: the error is due to the order of names. OrientDB import is quite rigid on that.
We faced this same issue some time ago. While trying to modify a backup, we prettified the json file for more ease of use. But due to the constraint of having ordered values and even not accepting white spaces between keys and values, we just abandoned the idea.
Pretending that the file is json is wrong IMO and it should be stated that it is only a subset of it. As objects in json are an unordered collection of key:value pairs and spaces between the comma and the key or value should not be taken into account.
You're right. I've added few notes on export/import pages about such constraints.
Thanks folks. The main reason for prettify-ing the JSON (er... exported file) is so it will diff better on github. Without that, it is one straight long line (i.e. no line breaks). Any solution for that?
(and the reason why we even check this file into git and version control it is so we can create a DB with a specific schema quickly. Are there any other non-export/import based recommended solution for that purpose? Using a java program for that seems like a lot of code with too much inline mash of data; I'd prefer a declarative approach like JSON description of the DB schema, which is what attracted me to the exported 'json' approach in the first place).
We miss the declarative approach but using sql batch mode seems to work pretty well. Especially if used mainly for DB schemas.
Thanks red-0ne. Yes, I tried the sql batch mode too at first, but it is too limiting - for e.g. you cannot create functions this way.
I wrote down my experiences at http://blog.thirumal.net/dev/2015/04/14/creating-an-orientdb-database-from-scratch/.
You can create function using batch mode
INSERT INTO OFunction (language, name, arameters, code) VALUES ("javascript", "concat", ["x", "y"], "return x + y;")
Suprisingly I cannot find a way to execute it from sql.
I still think that importing from json is a must have. Although being aware that this is not as simple as a JSON.parse(). The road is already half done.
@red-0ne You can invoke idempotent functions from select. Example:
select from myFunction(1,2)
Perfect! Thank you.
I was able to import an edited json export by running it through a minify before importing: http://www.httputility.net/json-minifier.aspx
The issue is not with minification, but with the ordering of the tokens.
On Mon, Jul 6, 2015 at 3:32 PM, sdiAlexis [email protected] wrote:
I was able to import an edited json export by running it through a minify before importing: http://www.httputility.net/json-minifier.aspx
— Reply to this email directly or view it on GitHub https://github.com/orientechnologies/orientdb/issues/3916#issuecomment-119016826 .