Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
feat(json): use semi-structured/json in TASK_MARSHAL and TASK_UNMAR…
Browse files Browse the repository at this point in the history
…SHAL (#62)

Because

- We've introduced `semi-structured/json` for handling JSON data.

This commit

- Utilizes `semi-structured/json` in TASK_MARSHAL and TASK_UNMARSHAL.
- Refines the task descriptions.

Note
- This commit is a breaking change.
  • Loading branch information
donch1989 authored Feb 13, 2024
1 parent 80df32e commit acbe2db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
26 changes: 12 additions & 14 deletions pkg/json/v0/config/tasks.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"TASK_MARSHAL": {
"instillShortDescription": "Marshal the JSON object into string.",
"instillShortDescription": "Convert JSON to a string.",
"input": {
"description": "Input",
"instillEditOnNodeFields": [
"object"
"json"
],
"instillUIOrder": 0,
"properties": {
"object": {
"description": "Json object to be marshaled",
"json": {
"description": "JSON to be marshaled",
"instillAcceptFormats": [
"object",
"semi-structured/*",
Expand All @@ -21,12 +21,11 @@
"reference"
],
"required": [],
"title": "Object",
"type": "object"
"title": "JSON"
}
},
"required": [
"object"
"json"
],
"title": "Input",
"type": "object"
Expand Down Expand Up @@ -55,7 +54,7 @@
}
},
"TASK_UNMARSHAL": {
"instillShortDescription": "Unmarshal the JSON object from string.",
"instillShortDescription": "Convert a string to JSON.",
"input": {
"description": "Input",
"instillEditOnNodeFields": [
Expand Down Expand Up @@ -87,22 +86,21 @@
"output": {
"description": "Output",
"instillEditOnNodeFields": [
"object"
"json"
],
"instillUIOrder": 0,
"properties": {
"object": {
"json": {
"description": "Object",
"instillEditOnNodeFields": [],
"instillFormat": "semi-structured/object",
"instillFormat": "semi-structured/json",
"instillUIOrder": 0,
"required": [],
"title": "Object",
"type": "object"
"title": "JSON"
}
},
"required": [
"object"
"json"
],
"title": "Output",
"type": "object"
Expand Down
4 changes: 2 additions & 2 deletions pkg/json/v0/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (e *Execution) Execute(inputs []*structpb.Struct) ([]*structpb.Struct, erro
output := structpb.Struct{Fields: make(map[string]*structpb.Value)}
switch e.Task {
case marshal:
b, err := protojson.Marshal(input.Fields["object"])
b, err := protojson.Marshal(input.Fields["json"])
if err != nil {
return nil, err
}
Expand All @@ -74,7 +74,7 @@ func (e *Execution) Execute(inputs []*structpb.Struct) ([]*structpb.Struct, erro
if err != nil {
return nil, err
}
output.Fields["object"] = structpb.NewStructValue(&obj)
output.Fields["json"] = structpb.NewStructValue(&obj)

default:
return nil, fmt.Errorf("not supported task: %s", e.Task)
Expand Down

0 comments on commit acbe2db

Please sign in to comment.