Connected:
Using code in How to use a shell script as a host application for Chrome host for mobile devices to send JSON from the client (application) to the host
#!/bin/bash
that leads to
{"message":"}"}
accepted in the client application.
The loop obviously does not commit the $c variable in the while .
With JSON input from client
{"text":"abc"}
using JavaScript, we could get a single JSON string property by checking the characters in the previous and next indexes
var result = ""; var i = 0; var input = '{"text":"abc"}'; while (i < input.length) { if (input[i - 2] === ":" && input[i - 1] === '"' || result.length) { result += input[i]; } if (input[i + 1] === '"' && input[i + 2] === "}") {
it has not yet been determined exactly how to hide the if conditions to bash from JavaScript to get one JSON property that matches the code above and is combined with the line following How to match the two string variables in the if statement in Bash? and how to combine string variables in bash? . And provided that the JSON object has nested properties using nested or multiple if conditions, you will need to correct the code several times so that the specific JSON is passed to the host.
The documentation describes the protocol.
Private Message Protocol
Chrome starts each own messaging server in a separate process and communicates with it using standard input (stdin) and standard output (Standard output). The same format is used to send messages in both directions: each message is serialized using JSON, UTF-8 encoding and precedes with the length of the 32-bit message in its own byte order.
Could not find answers to SO that specifically described the procedure for parsing JSON from stdin on the Chrome Native Messsaging application host using bash.
How to create a general solution or algorithm (including descriptions of each step necessary for the protocol and language) for parsing JSON sent from the client on the host from stdin , get and set the correct length of the 32-bit message in the byte order of the JSON response message that will be sent (e.g. echo ; printf ) to the client using Bash?
source share