jsonata-python 0.6.2__py3-none-any.whl → 0.6.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
jsonata/cli/__main__.py CHANGED
@@ -34,7 +34,7 @@ def get_options(argv: Optional[list[str]] = None) -> argparse.ArgumentParser:
34
34
  """
35
35
  parser = argparse.ArgumentParser(prog="jsonata", description="Pure Python JSONata CLI")
36
36
  parser.add_argument(
37
- "-v", "--version", action='version', version='%(prog)s 0.6.2')
37
+ "-v", "--version", action='version', version='%(prog)s 0.6.3')
38
38
 
39
39
  parser.add_argument(
40
40
  "-e", "--expression", metavar="<file>",
jsonata/jsonata.py CHANGED
@@ -512,15 +512,21 @@ class Jsonata:
512
512
  results = utils.Utils.create_sequence()
513
513
  if isinstance(input, utils.Utils.JList) and input.tuple_stream:
514
514
  results.tuple_stream = True
515
- if not (isinstance(input, list)):
515
+ if input is None:
516
+ # undefined input yields undefined output; skip filtering entirely
517
+ input = utils.Utils.create_sequence()
518
+ elif not (isinstance(input, list)):
516
519
  input = utils.Utils.create_sequence(input)
517
520
  if predicate.type == "number":
518
521
  index = int(predicate.value) # round it down - was Math.floor
519
522
  if index < 0:
520
523
  # count in from end of array
521
524
  index = len(input) + index
522
- item = input[index] if 0 <= index < len(input) else None
523
- if item is not None:
525
+ if 0 <= index < len(input):
526
+ item = input[index]
527
+ # Preserve JSON null at this index (vs. out-of-bounds, which is undefined)
528
+ if item is None:
529
+ item = utils.Utils.NULL_VALUE
524
530
  if isinstance(item, list):
525
531
  results = item
526
532
  else:
@@ -1915,6 +1921,7 @@ class Jsonata:
1915
1921
 
1916
1922
  self.input = None
1917
1923
  self.validate_input = True
1924
+ self.output_convert_nulls = True
1918
1925
 
1919
1926
  # Note: now and millis are implemented in Functions
1920
1927
  # environment.bind("now", defineFunction(function(picture, timezone) {
@@ -1951,6 +1958,24 @@ class Jsonata:
1951
1958
  def set_validate_input(self, validate_input: bool) -> None:
1952
1959
  self.validate_input = validate_input
1953
1960
 
1961
+ #
1962
+ # Checks whether output NULL_VALUE conversion is enabled
1963
+ #
1964
+ def is_output_convert_nulls(self) -> bool:
1965
+ return self.output_convert_nulls
1966
+
1967
+ #
1968
+ # Enable or disable output NULL_VALUE conversion. Enabled by default, which
1969
+ # returns both "JSONata null" and "JSONata undefined" as Python None.
1970
+ #
1971
+ # When disabled, output values may contain Utils.NULL_VALUE indicating
1972
+ # "JSONata null" while Python None indicates "JSONata undefined".
1973
+ # Manually calling Utils.convert_nulls(result) on a raw result will yield
1974
+ # the converted result.
1975
+ #
1976
+ def set_output_convert_nulls(self, output_convert_nulls: bool) -> None:
1977
+ self.output_convert_nulls = output_convert_nulls
1978
+
1954
1979
  def evaluate(self, input: Optional[Any], bindings: Optional[Frame] = None) -> Optional[Any]:
1955
1980
  # throw if the expression compiled with syntax errors
1956
1981
  if self.errors is not None:
@@ -1987,7 +2012,8 @@ class Jsonata:
1987
2012
  # if (typeof callback === "function") {
1988
2013
  # callback(null, it)
1989
2014
  # }
1990
- it = utils.Utils.convert_nulls(it)
2015
+ if self.output_convert_nulls:
2016
+ it = utils.Utils.convert_nulls(it)
1991
2017
  return it
1992
2018
  except Exception as err:
1993
2019
  # insert error message into structure
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jsonata-python
3
- Version: 0.6.2
3
+ Version: 0.6.3
4
4
  Summary: Pure Python implementation of JSONata
5
5
  Project-URL: Homepage, https://github.com/rayokota/jsonata-python
6
6
  Project-URL: Bug Reports, https://github.com/rayokota/jsonata-python/issues
@@ -3,16 +3,16 @@ jsonata/constants.py,sha256=WtdH_l_s5KD-SiOJ4GR2az7WpVgKB2HguXUnyfy4tvs,3017
3
3
  jsonata/datetimeutils.py,sha256=lCTGih5Qn4HZlqG2qcCniREaOt_2Dvxai5rpFq-hKj4,48609
4
4
  jsonata/functions.py,sha256=VoVVyK-9SS6CrseChFJkERqUxm7mPzcoIeALegwVztI,75709
5
5
  jsonata/jexception.py,sha256=AjyPmFyE7FecV--FLYHfcZFu-SkG1XKAEdvUQ1Ojuqo,12956
6
- jsonata/jsonata.py,sha256=mKoqLdVED7nQyCjNqxgPr5_IBV5nzLKdonXDVy0SXyk,84652
6
+ jsonata/jsonata.py,sha256=folX5QxiuXUZEO-KWGWRIkSUQmJgA92MdzIWIMaZcWw,85763
7
7
  jsonata/parser.py,sha256=VfWmD79PA_zp7uXUjbVY1E9CEwA60EG1EV2vEKue__M,55444
8
8
  jsonata/signature.py,sha256=6iQIgFSCH9Wv7Zhuu5U8PT-LVTtxY_qL8QMsGn5wGH4,20221
9
9
  jsonata/timebox.py,sha256=bnevNR_ONvKUiIZCJZEWsRiR0gCWTGOwn5RCY7dKqYc,2861
10
10
  jsonata/tokenizer.py,sha256=M5vEaYrMEr6UQwakDLz7dAAIXeJ7ZBPlqw9gYWTbcZM,12550
11
11
  jsonata/utils.py,sha256=kn2qjrp7et2NPT3T6XtF9g6Y5lIHWEHgA42hHXQz8rs,5834
12
12
  jsonata/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- jsonata/cli/__main__.py,sha256=XfgdzMQEvKd3xkgTpvUndn5ifgVi0j4fYrn2Oejzu1E,7121
14
- jsonata_python-0.6.2.dist-info/METADATA,sha256=9U-6dc9p-wUZaptm0-59-RUQsAT3kRgHUDGnIwKNSyo,17338
15
- jsonata_python-0.6.2.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
16
- jsonata_python-0.6.2.dist-info/entry_points.txt,sha256=a-W2yyT3IPhcC1q12BhKPcWnjNi3NXTZ3ZxoI9_UK88,54
17
- jsonata_python-0.6.2.dist-info/licenses/LICENSE,sha256=y16Ofl9KOYjhBjwULGDcLfdWBfTEZRXnduOspt-XbhQ,11325
18
- jsonata_python-0.6.2.dist-info/RECORD,,
13
+ jsonata/cli/__main__.py,sha256=H-fQAcuYLMH-dSy5t8_idF0DjMivjk3XNWBibsbPuiY,7121
14
+ jsonata_python-0.6.3.dist-info/METADATA,sha256=EDbZIoarzAvc114WL_3525KBm2JakadKu7uj-I6hak8,17338
15
+ jsonata_python-0.6.3.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
16
+ jsonata_python-0.6.3.dist-info/entry_points.txt,sha256=a-W2yyT3IPhcC1q12BhKPcWnjNi3NXTZ3ZxoI9_UK88,54
17
+ jsonata_python-0.6.3.dist-info/licenses/LICENSE,sha256=y16Ofl9KOYjhBjwULGDcLfdWBfTEZRXnduOspt-XbhQ,11325
18
+ jsonata_python-0.6.3.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.29.0
2
+ Generator: hatchling 1.30.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any