-
Notifications
You must be signed in to change notification settings - Fork 1
Draft: Update README #8
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,14 +2,17 @@ | |
|
|
||
| [](https://github.com/cyberstudio/jsonj/actions/workflows/go.yml) [](https://godoc.org/github.com/cyberstudio/jsonj) [](https://goreportcard.com/report/github.com/cyberstudio/jsonj) | ||
|
|
||
| JSONJ can be used to manipulate raw json input using _marks_ and custom _fragments generators_. | ||
| * Library guarantees valid json output syntax; | ||
| * Library doesn't validate output json semantic like unique keys. | ||
| The library seeks for marks in input json and applies fragment generators, producing a new json. | ||
| It works with rules that are combinations or marks and generators. | ||
|
|
||
| The library guarantees a valid output json syntax on valid input json. | ||
| Also, it is possible to generate a semantically invalid json if fragment generators are not correct. | ||
| For example, an incorrect fragment generator can produce duplicate object keys. | ||
|
|
||
| ## Marks | ||
|
|
||
| One can apply generator to _marks_ of json input. Each _mark_ is json key name. | ||
| For example, `uuid` and `id` maybe used as _mark_. | ||
| Each _mark_ is an object key name. One can apply generator to _marks_ of input. | ||
| For example, `uuid` and `id` can be used as _mark_. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Надо бы придумать пример получше, от этого куча wtf-ов вроде "зачем тут два id (и uuid, и id)?". Наверное, просто удалить uuid ок.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example, [
{
"id": 1234
},
{
"id": 1234
}
]Mark can be renamed in result of operation. It depends on Advice: wrap marks in special symbols, i.e.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ты вот так предлагаешь?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ага, так хорошо. |
||
| ```json | ||
| [ | ||
| { | ||
|
|
@@ -23,26 +26,26 @@ For example, `uuid` and `id` maybe used as _mark_. | |
| ] | ||
| ``` | ||
|
|
||
| _Mark_ maybe renamed in result of _operation_. It depends on `operation` mode and its rules. | ||
| _Mark_ can be renamed in result of _operation_. It depends on `operation` mode and its rules. | ||
|
|
||
| Advice: wrap _marks_ by special chars, i.e. `__uuid__` and unwrap during `operation`. | ||
| Advice: wrap _marks_ in special symbols, i.e. `__uuid__` and unwrap during `operation`. | ||
|
|
||
|
|
||
| ## Operations | ||
| Library supports number of operations, named _Mode_: | ||
| * `ModeInsert`: insert key/value pair after the _mark_. | ||
| * `ModeReplaceValue`: replace value, or convert it; | ||
| * `ModeReplace`: replace entire key/value pair; | ||
|
|
||
| The library supports a number of operations, named _Mode_: | ||
| * `ModeInsert`: insert key/value pair after the _mark_, | ||
| * `ModeReplace`: replace the entire key/value pair, | ||
| * `ModeReplaceValue`: replace or convert value and keep key as is, | ||
| * `ModeDelete`: delete key/value. | ||
|
|
||
| ## Fragments generators | ||
|
|
||
| Type `GenerateFragmentBatchFunc` describes interface of generators. | ||
| Key feature of generators is batch processing. Batches speed up result output. | ||
| Implement GenerateFragmentBatchFunc interface to create a custom fragment generator. | ||
|
|
||
| Example: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Совсем непонятный пример, конечно. Для того, чтобы он был понятным, нужно добавить пример входного и выходного json-а. Добавить больше комментов в коде. Возможно, не помешал бы какой-нибудь более жизненный и простой пример, а то сложно людям объяснить, в чём профит подклеивать поле url в объекты. |
||
| ```go | ||
| // GeneratorParams customize generator behavior | ||
| // GeneratorParams customizes generator behavior | ||
| type GeneratorParams struct{ | ||
| EmbedObjectURL bool | ||
| BaseURL string | ||
|
|
@@ -74,3 +77,5 @@ func Generator(ctx context.Context, iterator jsonj.FragmentIterator, p interface | |
| return result, nil | ||
| } | ||
| ``` | ||
|
|
||
| Batch processing is a key feature of generators. It speeds up the result output. | ||
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.
Звучит как ещё одна приятная фича библиотеки, хотя это не так :)
Лучше без Also, а после этого предложения написать что-нибудь вроде "Test your fragment generators".