Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | added json->string |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
16dfcae804d8c22a2a917bce1f395d68 |
User & Date: | aldo 2017-11-12 20:41:47 |
Context
2017-12-06
| ||
15:53 | added support for list of chars in string-split, added nest check-in: 37a97684bf user: aldo tags: trunk | |
2017-11-12
| ||
20:41 | added json->string check-in: 16dfcae804 user: aldo tags: trunk | |
20:41 | added sqlite3-trace check-in: 04c36a824f user: aldo tags: trunk | |
Changes
Changes to json.sls.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
185
186
187
188
189
190
191
192
193
194
|
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ;; See the License for the specific language governing permissions and ;; limitations under the License. #!chezscheme (library (json) (export parse-json-str read-file let-json-object string->json) (import (srfi s14 char-sets) (scheme)) (include "lalr/associators.ss") (include "lalr/lalr.ss") (define (parse-json-str pos data escaping out) (cond [(>= pos (string-length data)) ................................................................................ (define-syntax let-json-object (lambda (x) (syntax-case x () [(_ object (tag ...) body ...) #`(let #,(map (lambda (t) #`(#,t (let ([v (assq (quote #,t) object)]) (if v (cdr v) v))))#'(tag ...)) body ...)])))) ;;#!eof |
|
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
...
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ;; See the License for the specific language governing permissions and ;; limitations under the License. #!chezscheme (library (json) (export parse-json-str read-file let-json-object string->json json->string) (import (srfi s14 char-sets) (scheme) (only (data-structures) string-intersperse string-translate*)) (include "lalr/associators.ss") (include "lalr/lalr.ss") (define (parse-json-str pos data escaping out) (cond [(>= pos (string-length data)) ................................................................................ (define-syntax let-json-object (lambda (x) (syntax-case x () [(_ object (tag ...) body ...) #`(let #,(map (lambda (t) #`(#,t (let ([v (assq (quote #,t) object)]) (if v (cdr v) v))))#'(tag ...)) body ...)]))) (define (json->string json) (define special '((#\backspace . #\b) (#\newline . #\n) (#\alarm . #\a) (#\return . #\r) (#\tab #\t) (#\\ . #\\) (#\" . #\"))) (cond [(and (pair? json) (eq? (car json) 'dict)) (string-append "{\n" (string-intersperse (map (lambda (pair) (let ([k (car pair)] [v (cdr pair)]) (string-append " " (json->string k) " : " (json->string v)))) (cdr json)) ",\n") "\n}\n")] [(list? json) (string-append "[" (string-intersperse (map json->string json) ",") "]\n")] [(number? json) (number->string json)] [(string? json) (string-append "\"" (list->string (fold-right (lambda (x acc) (let ([q (assq x special)]) (if q (cons #\\ (cons (cdr q) acc)) (cons x acc)))) '() (string->list json))) "\"" )] [(symbol? json) (json->string (symbol->string json))] [else (json->string "")])) ) ;;#!eof |