[CDRIVER-2208] Introduce new API for Extended JSON spec 2.0 output Created: 11/Jul/17  Updated: 28/Oct/23  Resolved: 24/Jul/17

Status: Closed
Project: C Driver
Component/s: json, libbson
Affects Version/s: None
Fix Version/s: 1.7.0

Type: New Feature Priority: Major - P3
Reporter: Jeremy Mikola Assignee: Jeremy Mikola
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by PHPC-926 Implement Extended JSON spec Closed
is depended on by PHPC-941 Introduce API for converting BSON to ... Closed
Related
related to CDRIVER-2168 Escape JSON strings for regex, symbol... Closed
related to PHPC-828 Use canonical extended JSON for Times... Closed
is related to CDRIVER-2128 Support revised Extended JSON spec Closed

 Description   

For CDRIVER-2128, bson_as_json() was changed to output relaxed JSON from the Extended JSON spec.

This ticket aims to accomplish a few things:

  • Ensure bson_as_json() does not significantly change its output in 1.7.0.
  • Rename bson_as_extended_json() to bson_as_canonical_json(), which will output canonical JSON from the Extended JSON spec.
  • Create bson_as_relaxed_json() to output relaxed JSON from the Extended JSON spec.

Keeping bson_as_json()'s output largely unchanged will ensure that we do not introduce a subtle BC break for users depending on the structure of its current output (based on MongoDB 3.4's extended JSON syntax). Down the line, we can look at deprecating bson_as_json() once MongoDB 3.6 is released and its tools/shell are updated to handle the new format (TOOLS-1610).



 Comments   
Comment by Ramon Fernandez Marina [ 12/Sep/17 ]

Author:

{'username': u'ajdavis', 'name': u'A. Jesse Jiryu Davis', 'email': u'jesse@mongodb.com'}

Message:CDRIVER-2208 use bson_as_canonical_json
Branch:r1.7
https://github.com/mongodb/mongo-c-driver/commit/685cd8ccb77408fce0585410ec6920e2b8f629ae

Comment by Ramon Fernandez Marina [ 12/Sep/17 ]

Author:

{'username': u'ajdavis', 'name': u'Jeremy Mikola', 'email': u'jmikola@gmail.com'}

Message:CDRIVER-2208: bson_as_canonical_json() and bson_as_relaxed_json()

Introduce new functions for the canonical and relaxed formats from Extended
JSON Spec 2.0. This reverts previous changes to bson_as_json(), which might
have caused BC breaks. Maintain legacy bson_as_json() output for non-finite
values. Note that legacy mode will produce "nan" and "inf" literals, which
are not valid JSON.

Also adds helper function for appending sorted regex options and regression
tests for bson_as_json() and multiple types.
Branch:r1.7
https://github.com/mongodb/libbson/commit/6929d34e7af2ccdc1ce283daf72b4d4dff952849

Comment by Githook User [ 28/Jul/17 ]

Author:

{'email': 'jmikola@gmail.com', 'username': 'jmikola', 'name': 'Jeremy Mikola'}

Message: PHPC-941: Add MongoDB\BSON\toCanonicalJSON() and toRelaxedJSON()

In CDRIVER-2208, bson_as_json() (used by toJSON()) was reverted to its original output format. Canonical and relaxed extended JSON are now produced by bson_as_canonical_json() and bson_as_relaxed_json(), respectively. This commit removes toExtendedJSON() (added in 980f1fb01a3e693e6081d09ed8e3ed9c2d76162b) in favor of the new functions.

Implementations for the BSON functions have been moved to their own file, which is consistent with what we're doing for the APM subscriber functions.
Branch: master
https://github.com/mongodb/mongo-php-driver/commit/65f50910101bccaf235d0d1f5f48446bde183a4b

Comment by Jeremy Mikola [ 27/Jul/17 ]

Cherry-picked to r1.7: https://github.com/mongodb/libbson/commit/6929d34e7af2ccdc1ce283daf72b4d4dff952849

Comment by Githook User [ 25/Jul/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-2208 use bson_as_canonical_json
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/7c2fe66953207e91d8abe0449a5f37fa9f62aeb9

Comment by A. Jesse Jiryu Davis [ 24/Jul/17 ]

Jira automatically links to commits on master. Here's the commit on r1.7: https://github.com/mongodb/libbson/commit/6929d34e7af2ccdc1ce283daf72b4d4dff952849

Comment by Githook User [ 24/Jul/17 ]

Author:

{'email': 'jmikola@gmail.com', 'username': 'jmikola', 'name': 'Jeremy Mikola'}

Message: CDRIVER-2208: bson_as_canonical_json() and bson_as_relaxed_json()

Introduce new functions for the canonical and relaxed formats from Extended
JSON Spec 2.0. This reverts previous changes to bson_as_json(), which might
have caused BC breaks. Maintain legacy bson_as_json() output for non-finite
values. Note that legacy mode will produce "nan" and "inf" literals, which
are not valid JSON.

Also adds helper function for appending sorted regex options and regression
tests for bson_as_json() and multiple types.
Branch: master
https://github.com/mongodb/libbson/commit/fecb9665eb8df04c3058a26601e37c6a4c0581d2

Comment by Jeremy Mikola [ 20/Jul/17 ]

http://mongodbcr.appspot.com/143860001

Comment by A. Jesse Jiryu Davis [ 11/Jul/17 ]

I suggest you:

  • Diff from d1f95c23 to HEAD, many of the changes in bson.c and test-bson.c are related to CDRIVER-1947 / CDRIVER-2128. The changes to bson-json.c are about parsing and I think it's reasonably backwards-compatible, unlike the generator changes.
  • Right now we track awkwardly which JSON mode we're in. See, for example, _bson_as_json_visit_array and _bson_as_extended_json_visit_array. Maybe add a "json_mode_t" enum value to the bson_json_state_t struct to track whether we're in legacy / relaxed / extended mode. That should make the next steps easier.
  • Restore the old test_bson_json_timestamp and use the new versions of that test for bson_as_relaxed_json instead.
  • Restore some of the old "visit" functions like _bson_as_json_visit_binary / date_time / regex / dbpointer / code / codewscope and use the new versions of those functions for bson_as_relaxed_json's visitor table. I see that _bson_as_json_visit_double also changed but I don't think it significantly broke compatibility?
  • When I look through the test suite now it seems like, before the BSON Corpus tests, bson_as_json was very little tested. Perhaps adapt the contents of multi-type.json for one big test of the legacy bson_as_json.
Generated at Wed Feb 07 21:14:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.