Skip to content

Commit

Permalink
v0.2.22
Browse files Browse the repository at this point in the history
  • Loading branch information
yh202109 committed Sep 16, 2024
1 parent 0102c95 commit 2d4043e
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
example_cdtg.ipynb
example_files.ipynb
util_jsonutil.ipynb
example_clinical.ipynb
example_ectd.ipynb
example_ectd2.ipynb
Expand Down
192 changes: 192 additions & 0 deletions docs/util_jsonutil.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<!-- \n",
" # Copyright (C) 2023-2024 Y Hsu <[email protected]>\n",
" #\n",
" # This program is free software: you can redistribute it and/or modify\n",
" # it under the terms of the GNU General Public license as published by\n",
" # the Free software Foundation, either version 3 of the License, or\n",
" # any later version.\n",
" #\n",
" # This program is distributed in the hope that it will be useful,\n",
" # but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
" # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n",
" # GNU General Public License for more details\n",
" #\n",
" # You should have received a copy of the GNU General Public license\n",
" # along with this program. If not, see <https://www.gnu.org/license/> \n",
"-->"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# U/Data/JSON tools\n",
"\n",
"JavaScript Object Notation (JSON) is a data exchange format deigned to be \"minimal, portable, textual, and a subset of JavaScript\"[^1].\n",
"\n",
"The module `util.jsonutil` depends on package `json` [^1] and provide simplified interface for creating keys summary, extracting values by keys, and preview. \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## JSON Format Refresh\n",
"\n",
"JSON grammar, data structure, and conformance rules can be found in reference [^3]. \n",
"\n",
"Below is an example of using `json` to process a JSON object found in reference [^4]:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"import json \n",
"\n",
"ex1 = {\n",
" \"Image\": {\n",
" \"Width\": 800,\n",
" \"Height\": 600,\n",
" \"Title\": \"View from 15th Floor\",\n",
" \"Thumbnail\": {\n",
" \"Url\": \"http://na/image/481989943\",\n",
" \"Height\": 125,\n",
" \"Width\": 100\n",
" },\n",
" \"Animated\" : False,\n",
" \"IDs\": [116, 943, 234, 38793]\n",
" }\n",
"}\n",
"print(json.dumps(ex1, indent=2))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## JSON Schema"
]
},
{
"cell_type": "markdown",
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"source": [
"For a larger dataset, a foundation schema or structure template is helpful to infer, create, modify and validate JSON objects to ensure correct data exchange.\n",
"A brief history and links about JSON schema can be found in reference [^5].\n",
"A schema object describe the structure of elements within a JSON data object [^6].\n",
"\n",
"Please note that there are multiple Python tools available for generating JSON schema. \n",
"\n",
"To generate a schema from an object using package `genson`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"from genson import SchemaBuilder\n",
"\n",
"builder = SchemaBuilder()\n",
"builder.add_object(ex1['Image'])\n",
"builder.to_schema()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To generate a schema from a list of objects (records) using package `genson`: "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"ex2 = [ex1['Image']] + [\n",
" {\n",
" \"Width\": \"701\",\n",
" \"Height\": False,\n",
" \"Title\": \"View from 16th Floor\",\n",
" }\n",
"]\n",
"\n",
"builder = SchemaBuilder()\n",
"builder.add_object(ex2)\n",
"print(json.dumps(builder.to_schema(), indent=2))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The output of `to_schema()` is a dictionary type object and can be edited as needed.\n",
"The package `genson` also provides functions to update `builder`, and to create extended schema builder."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reference\n",
"\n",
"[^1]: IETF. (2014). RFC 7159: The JavaScript Object Notation (JSON) Data Interchange Format. ([web page])https://datatracker.ietf.org/doc/html/rfc7159.html#section-1))\n",
"[^2]: Python Software Foundation. (2024). json — JSON encoder and decoder. ([web page](https://docs.python.org/3/library/json.html#json-to-py-table))\n",
"[^3]: IETF. (2014). RFC 7159: The JavaScript Object Notation (JSON) Data Interchange Format. ([web page])https://datatracker.ietf.org/doc/html/rfc7159.html#section-2))\n",
"[^4]: IETF. (2014). RFC 7159: The JavaScript Object Notation (JSON) Data Interchange Format. ([web page])https://datatracker.ietf.org/doc/html/rfc7159.html#section-13))\n",
"[^5]: The JSON Schema Organization. (year). History of JSON Schema. ([web page](https://json-schema.org/overview/what-is-jsonschema#history-of-json-schema))\n",
"[^6]: The JSON Schema Organization. (year). Creating your first schema. ([web page](https://json-schema.org/learn/getting-started-step-by-step))\n",
"[&7]: wolverdude. (2024). genson 1.3.0. ([web page](https://pypi.org/project/genson/)) | ([github](https://github.com/wolverdude/genson/))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.1"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
3 changes: 1 addition & 2 deletions mtbp3/data/supp_ectd/fda_ectd4.0_ctocv1.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,7 @@
5.3.1.1.pseudo.11 Randomisation scheme (E3 16.1.7)
5.3.1.1.pseudo.12 Audit certificates report (E3 16.1.8)
5.3.1.1.pseudo.13 Statistical methods interim analysis plan (E3 16.1.9)
5.3.1.1.pseudo.14 Inter-laboratory standardisation methods quality
5.3.1.1.pseudo.15 assurance (E3 16.1.10)
5.3.1.1.pseudo.14 Inter-laboratory standardisation methods quality assurance (E3 16.1.10)
5.3.1.1.pseudo.16 Publications based on study (E3 16.1.11)
5.3.1.1.pseudo.17 Publications referenced in report (E3 16.1.12)
5.3.1.1.pseudo.18 Discontinued patients (E3 16.2.1)
Expand Down

0 comments on commit 2d4043e

Please sign in to comment.