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

Added support for multiline JSON parsing #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DeiNile
Copy link

@DeiNile DeiNile commented Jul 20, 2022

It is pretty common to send JSON over websockets, and it can be rather limiting to be forced to "minify" the JSON string, especially for local testing. The new '-j --json' flag is supposed to alleviate that. The primary way this is alleviated is by allowing for multiline inputs. Secondarily, by leveraging the built in JSON.parse() method we can check to see if the inputs produce a valid JSON string, and determine that the multiline input is terminated. Finally, as inspired by the Scala REPL, two consecutive empty lines resets the input.

Here are some samples of what this looks like while it is running:

$ wscat -j -c ws://websocket-echo.com
Connected (press CTRL+C to quit)
> {}
< {}
> []
< []
> {
|   "foo": "bar",
|   "hello": "world"
| }
< {
  "foo": "bar",
  "hello": "world"
}
> 42
< 42
> "hello world"
< "hello world"
> [
|   1,
|   2
|   ,3]
< [
  1,
  2
  ,3]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant