-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Parse JSON Notices Section #2669
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to run prettier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rerun pre-commit hooks.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2669 +/- ##
=====================================
Coverage 6.21% 6.21%
=====================================
Files 167 167
Lines 4231 4231
Branches 467 467
=====================================
Hits 263 263
Misses 3966 3966
Partials 2 2 ☔ View full report in Codecov by Sentry. |
app/routes/docs.client.samples.md
Outdated
|
||
## Parsing JSON | ||
|
||
Read the JSON data from [sample.schema.json](https://gcn.nasa.gov/docs/notices/schema) and [sample.example.json](https://gcn.nasa.gov/docs/notices/schema), which parses it into Python dictionaries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code sample below does not refer to a file called sample.schema.json
.
|
||
## Encoding and Decoding of Embedded Data | ||
|
||
The following code sample shows how to encode/decode a file in Python. The [`base64`](https://docs.python.org/3/library/base64.html#base64.b64encode) package includes the methods `b64decode` and `b64encode` to make this task simple. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following code sample shows how to encode/decode a file in Python.
It doesn't show how to encode/decode any file in Python; only how to encode/decode bytes to base64 for transfer over an ASCII medium.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following code sample shows how to encode/decode a file in Python. The [`base64`](https://docs.python.org/3/library/base64.html#base64.b64encode) package includes the methods `b64decode` and `b64encode` to make this task simple. | |
The following code demonstrates how to encode/decode a file using Python's built-in [`base64`](https://docs.python.org/3/library/base64.html#base64.b64encode) module. This module provides the `b64decode` and `b64encode` methods to make this task simple. | |
```python | |
import base64 | |
# Encode the content of a file to a Base64 string | |
with open("path/to/your/file", 'rb') as file: | |
encoded_string = base64.b64encode(file.read()) | |
print(encoded_string) | |
# Output: A Base64 encoded bytestring, e.g., b'a1512dabc1b6adb3cd1b6dcb6d4c6......' | |
with open("path/to/encoded_file.txt", 'wb') as encoded_file: | |
encoded_file.write(encoded_string) | |
# Decode and write the content to a local file: | |
with open("path/to/encoded_file.txt", 'rb') as encoded_file: | |
decoded_data = base64.b64decode(encoded_file.read()) | |
with open("path/to/destination/file", 'wb') as file: | |
file.write(decoded_data) |
@dakota002 could you please help for details?
} | ||
``` | ||
|
||
In your data production pipeline, you can use the encoding steps to convert your file to a bytestring and set the value of the property to this bytestring. See [non-JSON data](https://json-schema.org/understanding-json-schema/reference/non_json_data.html) for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great sample code, but not enough context here to understand what these instructions are for.
This encoding information needs to also be referenced somewhere in the creating JSON notices documentation. |
Add example of pulling message off the network and getting bytes out. |
This document includes how to parse, encode, decode the JSON Schema files.
Resolves: #2149
Previous branch (#2506) had 100+ commits behind, rebase was messy and touched many files.
Feedbacks need to be included:
-Provide hyperlinks to these Python methods.
-Please provide sample code for parsing Kafka records in a message consuming loop