### JSON Formatting The JSON format is used extensively for communication in the Ethereum circles. Writing a JSON-ish parser in K takes 6 lines. ```k module JSON imports INT imports STRING imports BOOL syntax JSONs ::= List{JSON,","} [klabel(JSONs) , symbol] syntax JSONKey ::= String syntax JSON ::= "null" [klabel(JSONnull) , symbol] | String | Int | Bool | JSONKey ":" JSON [klabel(JSONEntry) , symbol] | "{" JSONs "}" [klabel(JSONObject) , symbol] | "[" JSONs "]" [klabel(JSONList) , symbol] // -------------------------------------------------------------------- ``` **TODO**: Adding `Int` to `JSONKey` is a hack to make certain parts of semantics easier. ```k syntax JSONKey ::= Int // ---------------------- endmodule ``` JSON-RPC -------- ```k module JSON-RPC imports K-IO imports LIST imports JSON configuration $SOCK:Int 0:IOInt "":JSON 0:JSON "":JSON [ .JSONs ] undef .List syntax JSON ::= "undef" [klabel(JSON-RPCundef), symbol] // ------------------------------------------------------- syntax Bool ::= isProperJson ( JSON ) [function] | isProperJsonList ( JSONs ) [function] // ----------------------------------------------------- rule isProperJson(_) => false [owise] rule isProperJson(null) => true rule isProperJson(_:Int) => true rule isProperJson(_:Bool) => true rule isProperJson(_:String) => true rule isProperJson(_:JSONKey : J) => isProperJson(J) rule isProperJson([ JS ]) => isProperJsonList(JS) rule isProperJson({ JS }) => isProperJsonList(JS) rule isProperJsonList(.JSONs) => true rule isProperJsonList(J, JS) => isProperJson(J) andBool isProperJsonList(JS) endmodule ```