1module Language.JSON.Data
3import Data.String.Extra
15 | JObject (List (String, JSON))
19showChar : Char -> String
29 c => if isControl c || c >= '\127'
30 then "\\u" ++ b16ToHexString (fromInteger (cast (ord c)))
33showString : String -> String
34showString x = "\"" ++ concatMap showChar (unpack x) ++ "\""
36||| Convert a JSON value into its string representation.
37||| No whitespace is added.
38stringify : JSON -> String
39stringify JNull = "null"
40stringify (JBoolean x) = if x then "true" else "false"
41stringify (JNumber x) = show x
42stringify (JString x) = showString x
43stringify (JArray xs) = "[" ++ stringifyValues xs ++ "]"
45 stringifyValues : List JSON -> String
46 stringifyValues [] = ""
47 stringifyValues (x :: xs) = stringify x
50 else "," ++ stringifyValues xs
51stringify (JObject xs) = "{" ++ stringifyProps xs ++ "}"
53 stringifyProp : (String, JSON) -> String
54 stringifyProp (key, value) = showString key ++ ":" ++ stringify value
56 stringifyProps : List (String, JSON) -> String
57 stringifyProps [] = ""
58 stringifyProps (x :: xs) = stringifyProp x
61 else "," ++ stringifyProps xs
67||| Format a JSON value, indenting by `n` spaces per nesting level.
69||| @curr The current indentation amount, measured in spaces.
70||| @n The amount of spaces to indent per nesting level.
72format : {default 0 curr : Nat} -> (n : Nat) -> JSON -> String
73format {curr} n json = indent curr $ formatValue curr n json
75 formatValue : (curr, n : Nat) -> JSON -> String
76 formatValue _ _ (JArray []) = "[]"
77 formatValue curr n (JArray xs@(_ :: _)) = "[\n" ++ formatValues xs
80 formatValues : (xs : List JSON) -> {auto ok : NonEmpty xs} -> String
81 formatValues (x :: xs) = format {curr=(curr + n)} n x
82 ++ case nonEmpty xs of
83 Yes ok => ",\n" ++ formatValues xs
85 formatValue _ _ (JObject []) = "{}"
86 formatValue curr n (JObject xs@(_ :: _)) = "{\n" ++ formatProps xs
89 formatProp : (String, JSON) -> String
90 formatProp (key, value) = indent (curr + n) (showString key ++ ": ")
91 ++ formatValue (curr + n) n value
93 formatProps : (xs : List (String, JSON)) -> {auto ok : NonEmpty xs} -> String
94 formatProps (x :: xs) = formatProp x
95 ++ case nonEmpty xs of
96 Yes ok => ",\n" ++ formatProps xs
98 formatValue _ _ x = stringify x
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list