Skip to content
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

SCALE-native JSON value #5024

Open
0x009922 opened this issue Sep 2, 2024 · 2 comments · May be fixed by #5084
Open

SCALE-native JSON value #5024

0x009922 opened this issue Sep 2, 2024 · 2 comments · May be fixed by #5084
Assignees
Labels
api-changes Changes in the API for client libraries Enhancement New feature or request question Further information is requested

Comments

@0x009922
Copy link
Contributor

0x009922 commented Sep 2, 2024

Context

Continuation of:

In short, Iroha supports arbitrary JSON payloads for certain actions. In SCALE they are encoded as JSON strings (JsonString type), while in JSON format they are inlined as values.

This is a proposal of an alternative solution: introduce as SCALE-native JsonValue type, encoded not as a string, but directly as an enum:

enum JsonValue {
    Null,
    Bool(bool),
    Number(Number),
    String(String),
    Array(Vec<JsonValue>),
    Object(Map<String, JsonValue>),
}

this is a literal copy of serde_json::Value

Benefits

  • Compact encoding of JSON - no need to encode "[{}], characters & whitespace
  • Possibly faster deserialisation - needs benchmarking and careful implementation
  • Consistency in the schema - JsonValue represents f

Downsides

  • Needs custom implementation

Why it is String now

AFAIK the initial choice of string representation for JSON values is an efficiency concern: we don't want to pay for extra (de)serialization while transmitting data to/from WASM smartcontracts.

Basically, string was used as a way to have lazy encoding of data, as requested.

I think it should be possible to achieve lazy encoding in a more direct way with some sort of Lazy<T> container, making it both more explicit and flexible.

@0x009922 0x009922 added Enhancement New feature or request question Further information is requested api-changes Changes in the API for client libraries labels Sep 2, 2024
@DCNick3
Copy link
Contributor

DCNick3 commented Sep 2, 2024

Like the suggestion of the Lazy container, this could nicely decouple the laziness from the data type.

@dmitrivenger
Copy link

@0x009922 and @Erigara - guys can u plz take a look at this task? It blocks the Java SDK

@Erigara Erigara self-assigned this Sep 16, 2024
@Erigara Erigara linked a pull request Sep 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-changes Changes in the API for client libraries Enhancement New feature or request question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants