[JAVA-2447] Implement Extended JSON specification Created: 13/Feb/17  Updated: 28/Apr/19  Resolved: 21/Jul/17

Status: Closed
Project: Java Driver
Component/s: JSON
Affects Version/s: None
Fix Version/s: 3.5.0

Type: New Feature Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by DRIVERS-351 Implement Extended JSON Spec Implementing
Duplicate
duplicates JAVA-2439 MongoCursor returns the date variable... Closed
is duplicated by JAVA-2224 JsonReader does not support BsonRegul... Closed
is duplicated by JAVA-2454 Document.toJson incorrectly serialize... Closed
is duplicated by JAVA-1769 Support $numberLong convention when r... Closed
is duplicated by JAVA-2475 Handle out-of-order keys in Extended ... Closed
Related
is related to JAVA-2556 Change toJson method contract to defa... Closed
is related to JAVA-2173 add new Enum value for org.bson.json.... Closed
is related to JAVA-2489 Add to Enum<JsonMode> Closed

 Description   

Specification: https://github.com/mongodb/specifications/blob/master/source/extended-json.rst
Tests: https://github.com/mongodb/specifications/tree/master/source/bson-corpus/tests



 Comments   
Comment by Sivakeshavulu vadlamudi [ 28/Apr/19 ]

HI Jeff Yemin

 

com.mongodb.util.JSON.serialize is working properly is there any other alternate solution?

// or use a connection string// or use a connection string MongoClientURI connectionString = new MongoClientURI("mongodb://localhost:27017"); MongoClient mongoClient = new MongoClient(connectionString);
MongoDatabase database = mongoClient.getDatabase("testdb"); MongoCollection<Document> collection = database.getCollection("user"); //JsonWriterSettings writerSettings = new JsonWriterSettings(JsonMode.SHELL, true);            //System.out.println(doc.toJson(writerSettings)); Document myDoc = collection.find().first(); //System.out.println(myDoc.toJson(writerSettings)); System.out.println("output (JSON) = " + com.mongodb.util.JSON.serialize(myDoc));

 

 

output (JSON) = { "_id" :

{ "$oid" : "5cc2e1d4734a1f4d66966554"}

, "name" : "mkyong-updated" , "age" : 30 , "createdDate" : { "$date" : "2019-04-26T10:47:48.643Z"}}

 

Comment by sivakeshavulu [ 26/Apr/19 ]

Dear Jeff Yemin

can you please give me one java example for more understanding.

 

Comment by Jeffrey Yemin [ 26/Apr/19 ]

keshavlu4u

See our extended JSON specification at https://github.com/mongodb/specifications/blob/master/source/extended-json.rst#id10.

You may be looking for "Relaxed" extended JSON format, which is not the default but can be requested via the Document.toJson(JsonWriterSettings) overloaded method

Comment by sivakeshavulu [ 26/Apr/19 ]

Dear Jeff Yemin

Date format is wrong my MongoDb and  java Driver rutting the date is not same please refer below.

"createdDate" : ISODate("2019-04-26T10:47:48.643+0000") - MongodB collection data

"createdDate": {"$date": 1556275668643}} - Java Driver Reponse

 

Please help us

Expecting same as mongodb: 

i am facing issue on date (JAVA-2454) same issue.

Java Code

 

// or use a connection string// or use a connection string MongoClientURI connectionString = new MongoClientURI("mongodb://localhost:27017"); MongoClient mongoClient = new MongoClient(connectionString);
MongoDatabase database = mongoClient.getDatabase("testdb"); MongoCollection<Document> collection = database.getCollection("user"); Document myDoc = collection.find().first(); System.out.println(myDoc.toJson());

 

Reponse :{"_id":

{"$oid": "5cc2e1d4734a1f4d66966554"}

, "name": "mkyong-updated", "age": 30, "createdDate": {"$date": 1556275668643}}

 

 

MongoDB : 

{ "_id" : ObjectId("5cc2e1d4734a1f4d66966554"), "name" : "mkyong-updated", "age" : NumberInt(30), "createdDate" : ISODate("2019-04-26T10:47:48.643+0000") }

 

Comment by Githook User [ 21/Jul/17 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-2447: Implement revised extended JSON specification

Support new canonical and relaxed extended JSON forms

Change extended JSON parser to throw exceptions for documents
that have at least one of the reserved $-prefixed keys
but otherwise do not match the extended JSON form
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/775f75f49ef51df16c7ab15ad0fdd27cc05a73c9

Comment by Githook User [ 22/Mar/17 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-2447: Treat values that don't parse as the required types for extended JSON as an indication
that the document does not match the Extended JSON production and therefore should be treated as a
normal document.
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/b5135623e73ff38149ad2deba1b891f7f35bb222

Comment by Githook User [ 22/Mar/17 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-2447: Handle $-prefixed keys that don't match the extended JSON production by treating them as regular BSON documents
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/4627b5ad2239daa05b7066d679e32d4b30ecdf21

Comment by Githook User [ 16/Mar/17 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-2447: Remove Java 7/8 dependency for unsigned long operations
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/9d3c02c97e75fce5369c1a943a0e15c8cfa36c37

Comment by Githook User [ 15/Mar/17 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-2447: Support the Extended JSON specification.
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/ebe94bce0c5616cf8cfc0768949a84bd30cef1fd

Generated at Thu Feb 08 08:57:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.