1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 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 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
|
#Examples from http://json.org/example.html
a="{\"menu\": {
\"id\": \"file\",
\"value\": \"File\",
\"popup\": {
\"menuitem\": [
{\"value\": \"New\", \"onclick\": \"CreateNewDoc()\"},
{\"value\": \"Open\", \"onclick\": \"OpenDoc()\"},
{\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}
]
}
}}
"
b="{
\"glossary\": {
\"title\": \"example glossary\",
\"GlossDiv\": {
\"title\": \"S\",
\"GlossList\": {
\"GlossEntry\": {
\"ID\": \"SGML\",
\"SortAs\": \"SGML\",
\"GlossTerm\": \"Standard Generalized Markup Language\",
\"Acronym\": \"SGML\",
\"Abbrev\": \"ISO 8879:1986\",
\"GlossDef\": {
\"para\": \"A meta-markup language, used to create markup languages such as DocBook.\",
\"GlossSeeAlso\": [\"GML\", \"XML\"]
},
\"GlossSee\": \"markup\"
}
}
}
}
}
"
const c = """
{"widget": {
"debug": "on",
"window": {
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center"
},
"text": {
"data": "Click Here",
"size": 36.5,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}}"""
function validate_c(c)
j = JSON.parse(c)
@test j != nothing
@test typeof(j["widget"]["image"]["hOffset"]) == Int64
@test j["widget"]["image"]["hOffset"] == 250
@test typeof(j["widget"]["text"]["size"]) == Float64
@test j["widget"]["text"]["size"] == 36.5
end
d = "{\"web-app\": {
\"servlet\": [
{
\"servlet-name\": \"cofaxCDS\",
\"servlet-class\": \"org.cofax.cds.CDSServlet\",
\"init-param\": {
\"configGlossary:installationAt\": \"Philadelphia, PA\",
\"configGlossary:adminEmail\": \"ksm@pobox.com\",
\"configGlossary:poweredBy\": \"Cofax\",
\"configGlossary:poweredByIcon\": \"/images/cofax.gif\",
\"configGlossary:staticPath\": \"/content/static\",
\"templateProcessorClass\": \"org.cofax.WysiwygTemplate\",
\"templateLoaderClass\": \"org.cofax.FilesTemplateLoader\",
\"templatePath\": \"templates\",
\"templateOverridePath\": \"\",
\"defaultListTemplate\": \"listTemplate.htm\",
\"defaultFileTemplate\": \"articleTemplate.htm\",
\"useJSP\": false,
\"jspListTemplate\": \"listTemplate.jsp\",
\"jspFileTemplate\": \"articleTemplate.jsp\",
\"cachePackageTagsTrack\": 200,
\"cachePackageTagsStore\": 200,
\"cachePackageTagsRefresh\": 60,
\"cacheTemplatesTrack\": 100,
\"cacheTemplatesStore\": 50,
\"cacheTemplatesRefresh\": 15,
\"cachePagesTrack\": 200,
\"cachePagesStore\": 100,
\"cachePagesRefresh\": 10,
\"cachePagesDirtyRead\": 10,
\"searchEngineListTemplate\": \"forSearchEnginesList.htm\",
\"searchEngineFileTemplate\": \"forSearchEngines.htm\",
\"searchEngineRobotsDb\": \"WEB-INF/robots.db\",
\"useDataStore\": true,
\"dataStoreClass\": \"org.cofax.SqlDataStore\",
\"redirectionClass\": \"org.cofax.SqlRedirection\",
\"dataStoreName\": \"cofax\",
\"dataStoreDriver\": \"com.microsoft.jdbc.sqlserver.SQLServerDriver\",
\"dataStoreUrl\": \"jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon\",
\"dataStoreUser\": \"sa\",
\"dataStorePassword\": \"dataStoreTestQuery\",
\"dataStoreTestQuery\": \"SET NOCOUNT ON;select test='test';\",
\"dataStoreLogFile\": \"/usr/local/tomcat/logs/datastore.log\",
\"dataStoreInitConns\": 10,
\"dataStoreMaxConns\": 100,
\"dataStoreConnUsageLimit\": 100,
\"dataStoreLogLevel\": \"debug\",
\"maxUrlLength\": 500}},
{
\"servlet-name\": \"cofaxEmail\",
\"servlet-class\": \"org.cofax.cds.EmailServlet\",
\"init-param\": {
\"mailHost\": \"mail1\",
\"mailHostOverride\": \"mail2\"}},
{
\"servlet-name\": \"cofaxAdmin\",
\"servlet-class\": \"org.cofax.cds.AdminServlet\"},
{
\"servlet-name\": \"fileServlet\",
\"servlet-class\": \"org.cofax.cds.FileServlet\"},
{
\"servlet-name\": \"cofaxTools\",
\"servlet-class\": \"org.cofax.cms.CofaxToolsServlet\",
\"init-param\": {
\"templatePath\": \"toolstemplates/\",
\"log\": 1,
\"logLocation\": \"/usr/local/tomcat/logs/CofaxTools.log\",
\"logMaxSize\": \"\",
\"dataLog\": 1,
\"dataLogLocation\": \"/usr/local/tomcat/logs/dataLog.log\",
\"dataLogMaxSize\": \"\",
\"removePageCache\": \"/content/admin/remove?cache=pages&id=\",
\"removeTemplateCache\": \"/content/admin/remove?cache=templates&id=\",
\"fileTransferFolder\": \"/usr/local/tomcat/webapps/content/fileTransferFolder\",
\"lookInContext\": 1,
\"adminGroupID\": 4,
\"betaServer\": true}}],
\"servlet-mapping\": {
\"cofaxCDS\": \"/\",
\"cofaxEmail\": \"/cofaxutil/aemail/*\",
\"cofaxAdmin\": \"/admin/*\",
\"fileServlet\": \"/static/*\",
\"cofaxTools\": \"/tools/*\"},
\"taglib\": {
\"taglib-uri\": \"cofax.tld\",
\"taglib-location\": \"/WEB-INF/tlds/cofax.tld\"}}}"
const svg_tviewer_menu = """
{"menu": {
"header": "SVG\\tViewer\\u03b1",
"items": [
{"id": "Open"},
{"id": "OpenNew", "label": "Open New"},
null,
{"id": "ZoomIn", "label": "Zoom In"},
{"id": "ZoomOut", "label": "Zoom Out"},
{"id": "OriginalView", "label": "Original View"},
null,
{"id": "Quality"},
{"id": "Pause"},
{"id": "Mute"},
null,
{"id": "Find", "label": "Find..."},
{"id": "FindAgain", "label": "Find Again"},
{"id": "Copy"},
{"id": "CopyAgain", "label": "Copy Again"},
{"id": "CopySVG", "label": "Copy SVG"},
{"id": "ViewSVG", "label": "View SVG"},
{"id": "ViewSource", "label": "View Source"},
{"id": "SaveAs", "label": "Save As"},
null,
{"id": "Help"},
{"id": "About", "label": "About Adobe SVG Viewer..."}
]
}}"""
function validate_svg_tviewer_menu(str)
j = JSON.parse(str)
@test j != nothing
@test typeof(j) == Dict{String, Any}
@test length(j) == 1
@test typeof(j["menu"]) == Dict{String, Any}
@test length(j["menu"]) == 2
@test j["menu"]["header"] == "SVG\tViewerα"
@test isa(j["menu"]["items"], Vector{Any})
@test length(j["menu"]["items"]) == 22
@test j["menu"]["items"][3] == nothing
@test j["menu"]["items"][2]["id"] == "OpenNew"
@test j["menu"]["items"][2]["label"] == "Open New"
end
#Example JSON strings from http://www.jquery4u.com/json/10-example-json-files/
gmaps= "{\"markers\": [
{
\"point\":\"new GLatLng(40.266044,-74.718479)\",
\"homeTeam\":\"Lawrence Library\",
\"awayTeam\":\"LUGip\",
\"markerImage\":\"images/red.png\",
\"information\": \"Linux users group meets second Wednesday of each month.\",
\"fixture\":\"Wednesday 7pm\",
\"capacity\":\"\",
\"previousScore\":\"\"
},
{
\"point\":\"new GLatLng(40.211600,-74.695702)\",
\"homeTeam\":\"Hamilton Library\",
\"awayTeam\":\"LUGip HW SIG\",
\"markerImage\":\"images/white.png\",
\"information\": \"Linux users can meet the first Tuesday of the month to work out harward and configuration issues.\",
\"fixture\":\"Tuesday 7pm\",
\"capacity\":\"\",
\"tv\":\"\"
},
{
\"point\":\"new GLatLng(40.294535,-74.682012)\",
\"homeTeam\":\"Applebees\",
\"awayTeam\":\"After LUPip Mtg Spot\",
\"markerImage\":\"images/newcastle.png\",
\"information\": \"Some of us go there after the main LUGip meeting, drink brews, and talk.\",
\"fixture\":\"Wednesday whenever\",
\"capacity\":\"2 to 4 pints\",
\"tv\":\"\"
}
] }"
colors1 = "{
\"colorsArray\":[{
\"colorName\":\"red\",
\"hexValue\":\"#f00\"
},
{
\"colorName\":\"green\",
\"hexValue\":\"#0f0\"
},
{
\"colorName\":\"blue\",
\"hexValue\":\"#00f\"
},
{
\"colorName\":\"cyan\",
\"hexValue\":\"#0ff\"
},
{
\"colorName\":\"magenta\",
\"hexValue\":\"#f0f\"
},
{
\"colorName\":\"yellow\",
\"hexValue\":\"#ff0\"
},
{
\"colorName\":\"black\",
\"hexValue\":\"#000\"
}
]
}"
colors2 = "{
\"colorsArray\":[{
\"red\":\"#f00\",
\"green\":\"#0f0\",
\"blue\":\"#00f\",
\"cyan\":\"#0ff\",
\"magenta\":\"#f0f\",
\"yellow\":\"#ff0\",
\"black\":\"#000\"
}
]
}"
colors3 = "{
\"red\":\"#f00\",
\"green\":\"#0f0\",
\"blue\":\"#00f\",
\"cyan\":\"#0ff\",
\"magenta\":\"#f0f\",
\"yellow\":\"#ff0\",
\"black\":\"#000\"
}"
twitter = "{\"results\":[
{\"text\":\"@twitterapi http://tinyurl.com/ctrefg\",
\"to_user_id\":396524,
\"to_user\":\"TwitterAPI\",
\"from_user\":\"jkoum\",
\"metadata\":
{
\"result_type\":\"popular\",
\"recent_retweets\": 109
},
\"id\":1478555574,
\"from_user_id\":1833773,
\"iso_language_code\":\"nl\",
\"source\":\"<a href=\\\"http://twitter.com/\\\">twitter</a>\",
\"profile_image_url\":\"http://s3.amazonaws.com/twitter_production/profile_images/118412707/2522215727_a5f07da155_b_normal.jpg\",
\"created_at\":\"Wed, 08 Apr 2009 19:22:10 +0000\"}],
\"since_id\":0,
\"max_id\":1480307926,
\"refresh_url\":\"?since_id=1480307926&q=%40twitterapi\",
\"results_per_page\":15,
\"next_page\":\"?page=2&max_id=1480307926&q=%40twitterapi\",
\"completed_in\":0.031704,
\"page\":1,
\"query\":\"%40twitterapi\"}"
facebook= "{
\"data\": [
{
\"id\": \"X999_Y999\",
\"from\": {
\"name\": \"Tom Brady\", \"id\": \"X12\"
},
\"message\": \"Looking forward to 2010!\",
\"actions\": [
{
\"name\": \"Comment\",
\"link\": \"http://www.facebook.com/X999/posts/Y999\"
},
{
\"name\": \"Like\",
\"link\": \"http://www.facebook.com/X999/posts/Y999\"
}
],
\"type\": \"status\",
\"created_time\": \"2010-08-02T21:27:44+0000\",
\"updated_time\": \"2010-08-02T21:27:44+0000\"
},
{
\"id\": \"X998_Y998\",
\"from\": {
\"name\": \"Peyton Manning\", \"id\": \"X18\"
},
\"message\": \"Where's my contract?\",
\"actions\": [
{
\"name\": \"Comment\",
\"link\": \"http://www.facebook.com/X998/posts/Y998\"
},
{
\"name\": \"Like\",
\"link\": \"http://www.facebook.com/X998/posts/Y998\"
}
],
\"type\": \"status\",
\"created_time\": \"2010-08-02T21:27:44+0000\",
\"updated_time\": \"2010-08-02T21:27:44+0000\"
}
]
}"
const flickr = """{
"title": "Talk On Travel Pool",
"link": "http://www.flickr.com/groups/talkontravel/pool/",
"description": "Travel and vacation photos from around the world.",
"modified": "2009-02-02T11:10:27Z",
"generator": "http://www.flickr.com/",
"totalItems":222,
"items": [
{
"title": "View from the hotel",
"link": "http://www.flickr.com/photos/33112458@N08/3081564649/in/pool-998875@N22",
"media": {"m":"http://farm4.static.flickr.com/3037/3081564649_4a6569750c_m.jpg"},
"date_taken": "2008-12-04T04:43:03-08:00",
"description": "<p><a href=\\"http://www.flickr.com/people/33112458@N08/\\"> Talk On Travel</a> has added a photo to the pool:</p> <p><a href=\\"http:// www.flickr.com/photos/33112458@N08/3081564649/\\" title=\\"View from the hotel\\"> <img src=\\"http://farm4.static.flickr.com/3037/3081564649_4a6569750c_m.jpg\\" width=\\"240\\" height=\\"180\\" alt=\\"View from the hotel\\" /></a></p> ",
"published": "2008-12-04T12:43:03Z",
"author": "nobody@flickr.com (Talk On Travel)",
"author_id": "33112458@N08",
"tags": "spain dolphins tenerife canaries lagomera aqualand playadelasamericas junglepark losgigantos loscristines talkontravel"
}
]
}"""
function validate_flickr(str)
k = JSON.parse(str)
@test k != nothing
@test k["totalItems"] == 222
@test k["items"][1]["description"][12] == '\"'
end
youtube = "{\"apiVersion\":\"2.0\",
\"data\":{
\"updated\":\"2010-01-07T19:58:42.949Z\",
\"totalItems\":800,
\"startIndex\":1,
\"itemsPerPage\":1,
\"items\":[
{\"id\":\"hYB0mn5zh2c\",
\"uploaded\":\"2007-06-05T22:07:03.000Z\",
\"updated\":\"2010-01-07T13:26:50.000Z\",
\"uploader\":\"GoogleDeveloperDay\",
\"category\":\"News\",
\"title\":\"Google Developers Day US - Maps API Introduction\",
\"description\":\"Google Maps API Introduction ...\",
\"tags\":[
\"GDD07\",\"GDD07US\",\"Maps\"
],
\"thumbnail\":{
\"default\":\"http://i.ytimg.com/vi/hYB0mn5zh2c/default.jpg\",
\"hqDefault\":\"http://i.ytimg.com/vi/hYB0mn5zh2c/hqdefault.jpg\"
},
\"player\":{
\"default\":\"http://www.youtube.com/watch?v\u003dhYB0mn5zh2c\"
},
\"content\":{
\"1\":\"rtsp://v5.cache3.c.youtube.com/CiILENy.../0/0/0/video.3gp\",
\"5\":\"http://www.youtube.com/v/hYB0mn5zh2c?f...\",
\"6\":\"rtsp://v1.cache1.c.youtube.com/CiILENy.../0/0/0/video.3gp\"
},
\"duration\":2840,
\"aspectRatio\":\"widescreen\",
\"rating\":4.63,
\"ratingCount\":68,
\"viewCount\":220101,
\"favoriteCount\":201,
\"commentCount\":22,
\"status\":{
\"value\":\"restricted\",
\"reason\":\"limitedSyndication\"
},
\"accessControl\":{
\"syndicate\":\"allowed\",
\"commentVote\":\"allowed\",
\"rate\":\"allowed\",
\"list\":\"allowed\",
\"comment\":\"allowed\",
\"embed\":\"allowed\",
\"videoRespond\":\"moderated\"
}
}
]
}
}"
iphone = "{
\"menu\": {
\"header\": \"xProgress SVG Viewer\",
\"items\": [
{
\"id\": \"Open\"
},
{
\"id\": \"OpenNew\",
\"label\": \"Open New\"
},
null,
{
\"id\": \"ZoomIn\",
\"label\": \"Zoom In\"
},
{
\"id\": \"ZoomOut\",
\"label\": \"Zoom Out\"
},
{
\"id\": \"OriginalView\",
\"label\": \"Original View\"
},
null,
{
\"id\": \"Quality\"
},
{
\"id\": \"Pause\"
},
{
\"id\": \"Mute\"
},
null,
{
\"id\": \"Find\",
\"label\": \"Find...\"
},
{
\"id\": \"FindAgain\",
\"label\": \"Find Again\"
},
{
\"id\": \"Copy\"
},
{
\"id\": \"CopyAgain\",
\"label\": \"Copy Again\"
},
{
\"id\": \"CopySVG\",
\"label\": \"Copy SVG\"
},
{
\"id\": \"ViewSVG\",
\"label\": \"View SVG\"
},
{
\"id\": \"ViewSource\",
\"label\": \"View Source\"
},
{
\"id\": \"SaveAs\",
\"label\": \"Save As\"
},
null,
{
\"id\": \"Help\"
},
{
\"id\": \"About\",
\"label\": \"About xProgress CVG Viewer...\"
}
]
}
}"
customer = "{
\"firstName\": \"John\",
\"lastName\": \"Smith\",
\"age\": 25,
\"address\":
{
\"streetAddress\": \"21 2nd Street\",
\"city\": \"New York\",
\"state\": \"NY\",
\"postalCode\": \"10021\"
},
\"phoneNumber\":
[
{
\"type\": \"home\",
\"number\": \"212 555-1234\"
},
{
\"type\": \"fax\",
\"number\": \"646 555-4567\"
}
]
}"
product = "{
\"name\":\"Product\",
\"properties\":
{
\"id\":
{
\"type\":\"number\",
\"description\":\"Product identifier\",
\"required\":true
},
\"name\":
{
\"description\":\"Name of the product\",
\"type\":\"string\",
\"required\":true
},
\"price\":
{
\"type\":\"number\",
\"minimum\":0,
\"required\":true
},
\"tags\":
{
\"type\":\"array\",
\"items\":
{
\"type\":\"string\"
}
}
}
}"
interop = "{
\"ResultSet\": {
\"totalResultsAvailable\": \"1827221\",
\"totalResultsReturned\": 2,
\"firstResultPosition\": 1,
\"Result\": [
{
\"Title\": \"potato jpg\",
\"Summary\": \"Kentang Si bungsu dari keluarga Solanum tuberosum L ini ternyata memiliki khasiat untuk mengurangi kerutan jerawat bintik hitam dan kemerahan pada kulit Gunakan seminggu sekali sebagai\",
\"Url\": \"http://www.mediaindonesia.com/spaw/uploads/images/potato.jpg\",
\"ClickUrl\": \"http://www.mediaindonesia.com/spaw/uploads/images/potato.jpg\",
\"RefererUrl\": \"http://www.mediaindonesia.com/mediaperempuan/index.php?ar_id=Nzkw\",
\"FileSize\": 22630,
\"FileFormat\": \"jpeg\",
\"Height\": \"362\",
\"Width\": \"532\",
\"Thumbnail\": {
\"Url\": \"http://thm-a01.yimg.com/nimage/557094559c18f16a\",
\"Height\": \"98\",
\"Width\": \"145\"
}
},
{
\"Title\": \"potato jpg\",
\"Summary\": \"Introduction of puneri aloo This is a traditional potato preparation flavoured with curry leaves and peanuts and can be eaten on fasting day Preparation time 10 min\",
\"Url\": \"http://www.infovisual.info/01/photo/potato.jpg\",
\"ClickUrl\": \"http://www.infovisual.info/01/photo/potato.jpg\",
\"RefererUrl\": \"http://sundayfood.com/puneri-aloo-indian-%20recipe\",
\"FileSize\": 119398,
\"FileFormat\": \"jpeg\",
\"Height\": \"685\",
\"Width\": \"1024\",
\"Thumbnail\": {
\"Url\": \"http://thm-a01.yimg.com/nimage/7fa23212efe84b64\",
\"Height\": \"107\",
\"Width\": \"160\"
}
}
]
}
}"
const unicode = """
{"অলিম্পিকস": {
"অ্যাথলেট": "২২টি দেশ থেকে ২,০৩৫ জন প্রতিযোগী",
"ইভেন্ট": "২২টি ইভেন্টের মধ্যে ছিল দড়ি টানাটানি",
"রেকর্ড": [
{"১০০মি. স্প্রিন্ট": "রেজি ওয়াকার, দক্ষিণ আফ্রিকা"},
{"Marathon": "জনি হেইস"},
{" ফ্রি-স্টাইল সাঁতার": "Henry Taylor, Britain"}
]
}}
"""
function validate_unicode(str)
u = JSON.parse(str)
@test u != nothing
@test u["অলিম্পিকস"]["রেকর্ড"][2]["Marathon"] == "জনি হেইস"
end
|