Skip to content

Commit d691ff5

Browse files
committed
make typeof(null) be null, not null
update python, js, and golang codes update specification.yml
1 parent 24a97f3 commit d691ff5

File tree

8 files changed

+278
-11
lines changed

8 files changed

+278
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ result:
727727
- array
728728
- object
729729
- function
730-
- null # note: the value null, not the string "null"
730+
- null
731731
- '' # .. which interpolates to an empty string
732732
```
733733

jsone.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ var builtin = map[string]interface{}{
189189
case bool:
190190
return "boolean"
191191
case nil:
192-
return nil
192+
return "null"
193193
case []interface{}:
194194
return "array"
195195
case map[string]interface{}:

jsone/builtins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def typeof(v):
114114
elif isinstance(v, dict):
115115
return 'object'
116116
elif v is None:
117-
return None
117+
return 'null'
118118
elif callable(v):
119119
return 'function'
120120

jsone/newsfragments/246.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
make typeof(null) be "null", not null

jsone/render.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def interpolate(string, context):
4343
if isinstance(parsed, (list, dict)):
4444
raise TemplateError(
4545
"interpolation of '{}' produced an array or object".format(string[:offset]))
46-
if to_str(parsed) == "null":
46+
if parsed is None:
4747
result.append("")
4848
else:
4949
result.append(to_str(parsed))
@@ -56,7 +56,6 @@ def interpolate(string, context):
5656
if not mo:
5757
result.append(string)
5858
break
59-
6059
return ''.join(result)
6160

6261

specification.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,16 +1860,16 @@ result: object
18601860
title: typeof null
18611861
context: {x: null}
18621862
template: {$eval: 'typeof(x)'}
1863-
result: null
1863+
result: 'null'
18641864
---
18651865
title: typeof null, interpolated
18661866
context: {x: null}
18671867
template: "${typeof(x)}"
1868-
result: ''
1868+
result: 'null'
18691869
---
18701870
title: typeof null in if
18711871
context: {}
1872-
template: {$if: 'typeof(null) == null', then: 'foo', else: 'bar'}
1872+
template: {$if: 'typeof(null) == "null"', then: 'foo', else: 'bar'}
18731873
result: foo
18741874
---
18751875
title: typeof function
@@ -3726,9 +3726,9 @@ template: {$eval: 'key'}
37263726
result: {a: 1}
37273727
---
37283728
title: 'property with null value'
3729-
context: {key: null}
3729+
context: {key: 'null'}
37303730
template: {$eval: 'key'}
3731-
result: null
3731+
result: 'null'
37323732
---
37333733
title: 'missing property'
37343734
context: {key: {a: 1}}

src/builtins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ module.exports = (context) => {
132132
}
133133
}
134134
if (types['null'](x)) {
135-
return null;
135+
return 'null';
136136
}
137137
throw builtinError('builtin: typeof', `argument ${x} to be a valid json-e type. found ${typeof arg}`);
138138
},

0 commit comments

Comments
 (0)