Jim Tcl
Check-in [00e59d0dc4]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:json: Fix decode schema for list obj

Signed-off-by: Steve Bennett <steveb@workware.net.au>

Timelines: family | ancestors | descendants | both | trunk |
Files: files | file ages | folders
SHA1: 00e59d0dc42ba918bb75f817711d59c72d89aac6
User & Date: steveb@workware.net.au 2019-11-09 11:06:57
Context
2019-11-11
05:00
json: implement -index decode option check-in: 1477093252 user: dbohdan@dbohdan.com tags: trunk,
2019-11-09
11:06
json: Fix decode schema for list obj

Signed-off-by: Steve Bennett <steveb@workware.net.au> check-in: 00e59d0dc4 user: steveb@workware.net.au tags: trunk,

09:59
json: Add json encoder/decoder

Using the jsmn library for decoding. Based on the original implementation by Svyatoslav Mishyn <juef@openmailbox.org>

Signed-off-by: Steve Bennett <steveb@workware.net.au> check-in: 39428d770b user: steveb@workware.net.au tags: trunk,

Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to jim-json.c.

155
156
157
158
159
160
161



162
163
164
165
166
167
168
						if (json_decode_get_type(state->tok + i, state->json) != list_type) {
							/* Can't use list */
							container_type = JSON_MIXED;
							break;
						}
					}
				}



			}
		}
		json_decode_add_schema_type(interp, state, container_type);
		if (container_type == JSON_LIST && size) {
			json_decode_add_schema_type(interp, state, list_type);
		}
	}







>
>
>







155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
						if (json_decode_get_type(state->tok + i, state->json) != list_type) {
							/* Can't use list */
							container_type = JSON_MIXED;
							break;
						}
					}
				}
				else {
					container_type = JSON_MIXED;
				}
			}
		}
		json_decode_add_schema_type(interp, state, container_type);
		if (container_type == JSON_LIST && size) {
			json_decode_add_schema_type(interp, state, list_type);
		}
	}

Changes to tests/json.test.

91
92
93
94
95
96
97



98
99
100
101
102
103
104
	lindex [json::decode -schema {[1, 2, {a:["b", 1, true, ["d", "e", "f"]]}]}] 1
} {mixed num num {obj a {mixed str num bool {list str}}}}

test json-2.8 {schema tests} {
	lindex [json::decode -schema {[1, 2, true, false]}] 1
} {mixed num num bool bool}





unset -nocomplain json

test json-encode-1.1 {String with backslashes}  {
	json::encode {A "quoted string containing \backslashes\"}
} {"A \"quoted string containing \\backslashes\\\""}








>
>
>







91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
	lindex [json::decode -schema {[1, 2, {a:["b", 1, true, ["d", "e", "f"]]}]}] 1
} {mixed num num {obj a {mixed str num bool {list str}}}}

test json-2.8 {schema tests} {
	lindex [json::decode -schema {[1, 2, true, false]}] 1
} {mixed num num bool bool}

test json-2.9 {schema tests} {
	lindex [json::decode -schema {[{a:1},{b:2}]}] 1
} {mixed {obj a num} {obj b num}}

unset -nocomplain json

test json-encode-1.1 {String with backslashes}  {
	json::encode {A "quoted string containing \backslashes\"}
} {"A \"quoted string containing \\backslashes\\\""}