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

JSON Support #124

Closed
janewang opened this issue Apr 4, 2024 · 5 comments · Fixed by #249
Closed

JSON Support #124

janewang opened this issue Apr 4, 2024 · 5 comments · Fixed by #249
Assignees

Comments

@janewang
Copy link
Collaborator

janewang commented Apr 4, 2024

Developers have the option to request data in JSON format. By default, responses are in the current XDR+JSON format unless specified otherwise in the request. If JSON format is requested, the system will dynamically convert the XDR data to JSON for easier readability and use by developers.

In order to:

  • To request JSON format, include 'xdrFormat’: 'json' in the request.
  • To request the current XDR+JSON mixed response (how the API currently returns the response), simply don’t specify the xdrFormat in the request, or include 'xdrFormat': 'base64' in the request. The response will return the current JSON and XDR in base64 string.

The initial implementation is then backward compatible.

Example Usage for JSON response:

curl -X POST \
-H 'Content-Type: application/json' \
-H 'Accept': application/json \
-d '{
 "jsonrpc": "2.0",
 "id": 8675309,
 "method": "simulateTransaction",
 "params": {
   "xdrFormat": "json",
   "transaction": <in JSON>,
   "resourceConfig": {
     "instructionLeeway": 3000000
   }
 }
}' \
https://soroban-testnet.stellar.org:443 | jq

We have developed a canonical XDR ⇔ JSON schema for conversion between XDR and JSON: Stellar JSON

See https://docs.google.com/document/d/1tTuzL7HBHedp9TE-LonD1QV67SaBSReQ8YFj9xQIgtA/edit#heading=h.uedyb8nrk3a9

@sreuland sreuland modified the milestone: Sprint 48 May 22, 2024
@mollykarcher mollykarcher moved this from Backlog to To Do in Platform Scrum May 29, 2024
@mollykarcher mollykarcher added this to the platform sprint 47 milestone May 29, 2024
@mollykarcher
Copy link
Contributor

@janewang FYI unpackxdr being at the top-level breaks the json-rpc spec. I updated the description here to move it to within params. Cool with you?

@Shaptic
Copy link
Contributor

Shaptic commented Jun 25, 2024

@janewang @mollykarcher suggestion: asking the user to pass a parameter "format": "xdr" | "json" rather than unpackxdr

@janewang
Copy link
Collaborator Author

@Shaptic I think that's where we started with. However, the format of the rpc response is technically already in JSON, with XDR strings.

@Shaptic
Copy link
Contributor

Shaptic commented Jun 25, 2024

xdr_format: "json" | "base64" then? The idea is to not lock us into just JSON for unpacking XDR in the future 🤷‍♂️

@janewang
Copy link
Collaborator Author

janewang commented Jun 26, 2024

Fine with preserving the option to unpack XDR to another format. However, I think after we unpack to JSON, convert to other formats should not be the responsibility at this layer.

I think xdrFormat: "json" | "base64" is reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants