Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
1
Task/JSON/AntLang/json.antlang
Normal file
1
Task/JSON/AntLang/json.antlang
Normal file
|
|
@ -0,0 +1 @@
|
|||
json:{[data]catch[eval[,|{[y]catch[{":" = "="; "[" = "<"; "]" = ">"; "," = ";"}[y];{x};{[]y}]}'("""("(\\.|[^\\"])*"|\-?[0-9]+(\.[0-9]+)?|\{|\}|\[|\]|\:|\,)"""~data)["strings"]];{x};{error["Invalid JSON"]}]}
|
||||
14
Task/JSON/Apex/json.apex
Normal file
14
Task/JSON/Apex/json.apex
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
class TestClass{
|
||||
String foo {get;set;}
|
||||
Integer bar {get;set;}
|
||||
}
|
||||
|
||||
TestClass testObj = new TestClass();
|
||||
testObj.foo = 'ABC';
|
||||
testObj.bar = 123;
|
||||
|
||||
String serializedString = JSON.serialize(testObj);
|
||||
TestClass deserializedObject = (TestClass)JSON.deserialize(serializedString, TestClass.class);
|
||||
|
||||
//"testObj.foo == deserializedObject.foo" is true
|
||||
//"testObj.bar == deserializedObject.bar" is true
|
||||
34
Task/JSON/EchoLisp/json.echolisp
Normal file
34
Task/JSON/EchoLisp/json.echolisp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
;; JSON standard types : strings, numbers, and arrays (vectors)
|
||||
(export-json #(6 7 8 9)) → "[6,7,8,9]"
|
||||
(export-json #("alpha" "beta" "gamma")) → "["alpha","beta","gamma"]"
|
||||
|
||||
(json-import "[6,7,8,9]") → #( 6 7 8 9)
|
||||
(json-import #<< ["alpha","beta","gamma"] >>#) → #( "alpha" "beta" "gamma")
|
||||
|
||||
;; EchoLisp types : dates, rational, complex, big int
|
||||
(export-json 3/4) → "{"_instanceof":"Rational","a":3,"b":4}"
|
||||
(json-import #<< {"_instanceof":"Rational","a":666,"b":42} >>#) → 111/7
|
||||
|
||||
;; Symbols
|
||||
(export-json 'Simon-Gallubert) → "{"_instanceof":"Symbol","name":"Simon-Gallubert"}"
|
||||
(json-import #<< {"_instanceof":"Symbol","name":"Antoinette-de-Gabolde"} >>#)
|
||||
→ Antoinette-de-Gabolde
|
||||
|
||||
;; Lists
|
||||
(define my-list
|
||||
(export-json '( 43 4 5 ( 6 7 ( 8 9 )))))
|
||||
→ "{"_instanceof":"List" ,"array":[43,4,5,{"_instanceof":"List",
|
||||
"array":[6,7,{"_instanceof":"List",
|
||||
"array":[8,9],"circular":false}],"circular":false}],"circular":false}"
|
||||
|
||||
(json-import my-list) → (43 4 5 (6 7 (8 9)))
|
||||
|
||||
;; Structures
|
||||
(struct Person (name pict)) → #struct:Person [name pict]
|
||||
(define antoinette (Person "antoinette" "👰")) → # (antoinette 👰)
|
||||
|
||||
(export-json antoinette) →
|
||||
"{"_instanceof":"Struct", "struct":"Person","id":17,"fields":["antoinette","👰"]}"
|
||||
(json-import
|
||||
#<< {"_instanceof":"Struct","struct":"Person","id":18,"fields":["simon","🎩"]} >>#)
|
||||
→ # (simon 🎩)
|
||||
1
Task/JSON/FunL/json-1.funl
Normal file
1
Task/JSON/FunL/json-1.funl
Normal file
|
|
@ -0,0 +1 @@
|
|||
println( eval('{ "foo": 1, "bar": [10, "apples"] }') )
|
||||
3
Task/JSON/FunL/json-2.funl
Normal file
3
Task/JSON/FunL/json-2.funl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import json.*
|
||||
|
||||
DefaultJSONWriter.write( JSONReader({'ints', 'bigInts'}).fromString('{ "foo": 1, "bar": [10, "apples"] }') )
|
||||
2
Task/JSON/Harbour/json-1.harbour
Normal file
2
Task/JSON/Harbour/json-1.harbour
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
LOCAL arr
|
||||
hb_jsonDecode( '[101,[26,"Test1"],18,false]', @arr )
|
||||
4
Task/JSON/Harbour/json-2.harbour
Normal file
4
Task/JSON/Harbour/json-2.harbour
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
LOCAL arr := { 101, { 18, "Test1" }, 18, .F. }
|
||||
? hb_jsonEncode( arr )
|
||||
// The output is:
|
||||
// [101,[26,"Test1"],18,false]
|
||||
15
Task/JSON/Hoon/json.hoon
Normal file
15
Task/JSON/Hoon/json.hoon
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
:- %say
|
||||
|= [^ [in=@tas ~] ~]
|
||||
:- %noun
|
||||
=+ obj=(need (poja in)) :: try parse to json
|
||||
=+ typ=$:(name=@tas age=@ud) :: datastructure
|
||||
=+ spec=(ot name/so age/ni ~):jo :: parsing spec
|
||||
?. ?=([%o *] obj) :: isnt an object?
|
||||
~
|
||||
=+ ^= o
|
||||
%. %. (spec obj) :: parse with spec
|
||||
need :: panic if failed
|
||||
,typ :: cast to type
|
||||
=. age.o +(age.o) :: increment its age...
|
||||
%: crip %: pojo :: pretty-print result
|
||||
(jobe [%name s/name.o] [%age n/(crip <age.o>)] ~) :: convert back to json
|
||||
1
Task/JSON/LFE/json-1.lfe
Normal file
1
Task/JSON/LFE/json-1.lfe
Normal file
|
|
@ -0,0 +1 @@
|
|||
(: jiffy encode (list 1 2 3 '"apple" 'true 3.14))
|
||||
2
Task/JSON/LFE/json-2.lfe
Normal file
2
Task/JSON/LFE/json-2.lfe
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(: erlang binary_to_list
|
||||
(: jiffy encode (list 1 2 3 '"apple" 'true 3.14)))
|
||||
1
Task/JSON/LFE/json-3.lfe
Normal file
1
Task/JSON/LFE/json-3.lfe
Normal file
|
|
@ -0,0 +1 @@
|
|||
(: jiffy decode '"[1,2,3,[97,112,112,108,101],true,3.14]")
|
||||
1
Task/JSON/LFE/json-4.lfe
Normal file
1
Task/JSON/LFE/json-4.lfe
Normal file
|
|
@ -0,0 +1 @@
|
|||
(: jiffy decode '"{\"foo\": [1, 2, 3]}")
|
||||
3
Task/JSON/LFE/json-5.lfe
Normal file
3
Task/JSON/LFE/json-5.lfe
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(let (((tuple (list (tuple key value)))
|
||||
(: jiffy decode '"{\"foo\": [1, 2, 3]}")))
|
||||
(: io format '"~p: ~p~n" (list key value)))
|
||||
35
Task/JSON/Lasso/json.lasso
Normal file
35
Task/JSON/Lasso/json.lasso
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// Javascript objects are represented by maps in Lasso
|
||||
local(mymap = map(
|
||||
'success' = true,
|
||||
'numeric' = 11,
|
||||
'string' = 'Eleven'
|
||||
))
|
||||
|
||||
json_serialize(#mymap) // {"numeric": 11,"string": "Eleven","success": true}
|
||||
'<br />'
|
||||
|
||||
// Javascript arrays are represented by arrays
|
||||
local(opendays = array(
|
||||
'Monday',
|
||||
'Tuesday'
|
||||
))
|
||||
|
||||
local(closeddays = array(
|
||||
'Wednesday',
|
||||
'Thursday',
|
||||
'Friday'
|
||||
))
|
||||
|
||||
json_serialize(#opendays) // ["Monday", "Tuesday"]
|
||||
'<br />'
|
||||
json_serialize(#closeddays) // ["Wednesday", "Thursday", "Friday"]
|
||||
'<br />'
|
||||
|
||||
#mymap -> insert('Open' = #opendays)
|
||||
#mymap -> insert('Closed' = #closeddays)
|
||||
|
||||
local(myjson = json_serialize(#mymap))
|
||||
#myjson // {"Closed": ["Wednesday", "Thursday", "Friday"],"numeric": 11,"Open": ["Monday", "Tuesday"],"string": "Eleven","success": true}
|
||||
'<br />'
|
||||
|
||||
json_deserialize(#myjson) // map(Closed = array(Wednesday, Thursday, Friday), numeric = 11, Open = array(Monday, Tuesday), string = Eleven, success = true)
|
||||
45
Task/JSON/Lingo/json-1.lingo
Normal file
45
Task/JSON/Lingo/json-1.lingo
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
//--------------------------------------
|
||||
// Simple (unsafe) JSON decoder based on eval()
|
||||
// @param {string} json
|
||||
// @return {any}
|
||||
//--------------------------------------
|
||||
function json_decode (json){
|
||||
var o;
|
||||
eval('o='+json);
|
||||
return _json_decode_val(o);
|
||||
}
|
||||
|
||||
function _json_decode_val (o){
|
||||
if (o==null) return undefined;
|
||||
switch(typeof(o)){
|
||||
case "object":
|
||||
if (o instanceof Array){
|
||||
var v = list();
|
||||
var cnt = o.length;
|
||||
for (i=0;i<cnt;i++){
|
||||
v.add(_json_decode_val(o[i]));
|
||||
}
|
||||
}else{
|
||||
var v = propList();
|
||||
for (var i in o){
|
||||
var p = i;
|
||||
v.setAProp(_json_decode_val(p), _json_decode_val(o[i]));
|
||||
}
|
||||
}
|
||||
return v;
|
||||
case "string":
|
||||
// optional support of special Lingo data type 'symbol' unknown to JavaScript
|
||||
if (o.substr(0,7)=='__sym__') return symbol(o.substr(7));
|
||||
return o;
|
||||
default:
|
||||
return o;
|
||||
}
|
||||
}
|
||||
|
||||
function _json_escape_string (str){
|
||||
var hash={"\\":"\\\\", "/":"\\/", "\n":"\\n", "\t":"\\t", "\r":"\\r", "\b":"\\b", "\f":"\\f", "\"":"\\\""};
|
||||
var patt = "["; for (i in hash) patt+=i;patt+="]";
|
||||
return str.replace(RegExp(patt, "g"), function(c){
|
||||
return hash[c]
|
||||
});
|
||||
}
|
||||
50
Task/JSON/Lingo/json-2.lingo
Normal file
50
Task/JSON/Lingo/json-2.lingo
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
----------------------------------------
|
||||
-- JSON encoder
|
||||
-- Supported Lingo data types: VOID, integer, float, string, symbol, list, propList
|
||||
-- @param {any} o
|
||||
-- @return {string}
|
||||
----------------------------------------
|
||||
on json_encode (o)
|
||||
case ilk(o) of
|
||||
#void:
|
||||
return "null"
|
||||
#integer, #float:
|
||||
return string(o)
|
||||
#string:
|
||||
return QUOTE & _json_escape_string(o) & QUOTE
|
||||
#list:
|
||||
res = []
|
||||
repeat with v in o
|
||||
res.add(json_encode(v))
|
||||
end repeat
|
||||
return "[" & _cimplode(res) & "]"
|
||||
#propList:
|
||||
res = []
|
||||
cnt = count(o)
|
||||
repeat with i = 1 to cnt
|
||||
p = o.getPropAt(i)
|
||||
v = o[i]
|
||||
res.add( json_encode(p)&":"&json_encode(v) )
|
||||
end repeat
|
||||
return "{" & _cimplode(res) & "}"
|
||||
#symbol:
|
||||
-- optional support of special Lingo data type 'symbol' unknown to JavaScript
|
||||
return QUOTE &"__sym__"&_json_escape_string(string(o)) & QUOTE
|
||||
otherwise:
|
||||
put "ERROR: unsupported data type"
|
||||
end case
|
||||
end
|
||||
|
||||
----------------------------------------
|
||||
-- Implodes list into comma-separated string
|
||||
-- @param {list} l
|
||||
-- @return {string}
|
||||
----------------------------------------
|
||||
on _cimplode (l)
|
||||
str=""
|
||||
repeat with i=1 to l.count
|
||||
put l[i]&"," after str
|
||||
end repeat
|
||||
delete the last char of str
|
||||
return str
|
||||
end
|
||||
16
Task/JSON/Lingo/json-3.lingo
Normal file
16
Task/JSON/Lingo/json-3.lingo
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
data_org = [\
|
||||
42,\
|
||||
3.14159,\
|
||||
[2, 4, #fooBar, "apples", "bananas", "cherries" ],\
|
||||
["foo": 1, #bar: VOID, "Hello": "world!"],\
|
||||
VOID\
|
||||
]
|
||||
|
||||
json_str = json_encode(data_org) -- valid according to JSONLint
|
||||
|
||||
data_decoded = json_decode(json_str)
|
||||
|
||||
put data_org
|
||||
-- [42, 3.1416, [2, 4, #fooBar, "apples", "bananas", "cherries"], ["foo": 1, #bar: <Void>, "Hello": "world!"], <Void>]
|
||||
put data_decoded
|
||||
-- [42, 3.1416, [2, 4, #fooBar, "apples", "bananas", "cherries"], ["foo": 1, #bar: <Void>, "Hello": "world!"], <Void>]
|
||||
8
Task/JSON/Nim/json.nim
Normal file
8
Task/JSON/Nim/json.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import json
|
||||
|
||||
var data = parseJson("""{ "foo": 1, "bar": [10, "apples"] }""")
|
||||
echo data["foo"]
|
||||
echo data["bar"]
|
||||
|
||||
var js = %[%{"name": %"John", "age": %30}, %{"name": %"Susan", "age": %31}]
|
||||
echo js
|
||||
10
Task/JSON/Oforth/json.oforth
Normal file
10
Task/JSON/Oforth/json.oforth
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
>{"parents":["Otmar Gutmann", "Silvio Mazzola"], "name":"Pingu", "born":1986} .s
|
||||
[1] (Json) {"parents" : ["Otmar Gutmann", "Silvio Mazzola"], "name" : "Pingu", "born" : 1986 }
|
||||
ok
|
||||
>asString .s
|
||||
[1] (String) {"parents" : ["Otmar Gutmann", "Silvio Mazzola"], "name" : "Pingu", "born" :1986 }
|
||||
ok
|
||||
>perform .s
|
||||
[1] (Json) {"parents" : ["Otmar Gutmann", "Silvio Mazzola"], "name" : "Pingu", "born" : 1986 }
|
||||
ok
|
||||
>
|
||||
5
Task/JSON/Sidef/json.sidef
Normal file
5
Task/JSON/Sidef/json.sidef
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
var json = require('JSON').new;
|
||||
var data = json.decode('{"blue": [1, 2], "ocean": "water"}');
|
||||
say data;
|
||||
data{:ocean} = Hash.new(water => %w[fishy salty]);
|
||||
say json.encode(data);
|
||||
19
Task/JSON/Swift/json.swift
Normal file
19
Task/JSON/Swift/json.swift
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import Foundation
|
||||
|
||||
let jsonString = "{ \"foo\": 1, \"bar\": [10, \"apples\"] }"
|
||||
if let jsonData = jsonString.dataUsingEncoding(NSUTF8StringEncoding) {
|
||||
if let jsonObject : AnyObject = NSJSONSerialization.JSONObjectWithData(jsonData, options: .AllowFragments, error: nil) {
|
||||
println("NSDictionary: \(jsonObject)")
|
||||
}
|
||||
}
|
||||
|
||||
let obj = [
|
||||
"foo": [1, "Orange"],
|
||||
"bar": 1
|
||||
]
|
||||
|
||||
if let objData = NSJSONSerialization.dataWithJSONObject(obj, options: .PrettyPrinted, error: nil) {
|
||||
if let jsonString2 = NSString(data: objData, encoding: NSUTF8StringEncoding) {
|
||||
println("JSON: \(jsonString2)")
|
||||
}
|
||||
}
|
||||
1
Task/JSON/jq/json-1.jq
Normal file
1
Task/JSON/jq/json-1.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
.
|
||||
1
Task/JSON/jq/json-2.jq
Normal file
1
Task/JSON/jq/json-2.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
jq -c . data.json
|
||||
1
Task/JSON/jq/json-3.jq
Normal file
1
Task/JSON/jq/json-3.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
jq tostring data.json
|
||||
Loading…
Add table
Add a link
Reference in a new issue