Skip to main content

lvjson

Read and write LabVIEW Flatten To JSON text from Python: the NaN and Infinity tokens, LabVIEW's exact 20-digit numbers, negative zero, and strict portable JSON for everything else.

Every statement here about what LabVIEW writes or reads is pinned to output captured from LabVIEW 2026 and checked by the test suite. Pure Python, typed, no dependencies.

  • Guide: every function, the options, the number forms, errors, the command line and the evidence.
  • Changelog

Install

pip install lvjson

Python 3.10 or newer.

Quick start

>>> import lvjson
>>> text = '{"Data":[NaN,Infinity,-Infinity,0.10000000000000000555,-0]}'
>>> data = lvjson.loads(text)
>>> data
{'Data': [nan, inf, -inf, 0.1, -0.0]}
>>> lvjson.to_portable(text)
'{"Data":[null,null,null,0.1,-0.0]}'
>>> lvjson.dumps(data, number_style="labview") == text
True
>>> lvjson.dumps(data)
'{"Data":[NaN,Infinity,-Infinity,0.1,-0.0]}'
>>> lvjson.count_nonfinite(text)
{'NaN': 1, 'Infinity': 1, '-Infinity': 1}

loads also reads the Inf / -Inf spelling other producers use, never inside strings. nan_inf decides what non-finite values become at the boundary: kept ("extend"), null, or an LVJSONError ("reject"):

>>> lvjson.loads('[Inf, -Inf, "Inf", 1e400]', nan_inf="null")
[None, None, 'Inf', None]
>>> lvjson.dumps([float("nan")], nan_inf="reject")
Traceback (most recent call last):
  ...
lvjson.LVJSONError: non-finite float is not allowed under nan_inf='reject'
>>> lvjson.round_trip('{"v": 3.141592653589793116}')
'{"v":3.141592653589793}'
Function Purpose
loads(text, nan_inf=) Parse LabVIEW JSON (str, or UTF-8 bytes / bytearray)
dumps(obj, nan_inf=, infinity=, number_style=, indent=, sort_keys=) Serialise for LabVIEW
to_portable(text, nan_inf="null", indent=, sort_keys=) LabVIEW text to strict RFC 8259 JSON
to_labview(text, nan_inf=, infinity=, number_style=, indent=, sort_keys=) JSON text to LabVIEW text
round_trip(text, ...) Re-emit LabVIEW text canonically, values unchanged
count_nonfinite(text) Count each non-finite spelling outside strings
has_nonfinite(obj) Whether a parsed value holds NaN or an infinity

number_style="labview" writes doubles the way Flatten To JSON does: 20 significant digits in C's %g layout, exact ties rounded away from zero. "shortest" (the default) writes the shortest text that reads back as the same double. Both keep every double exact. infinity="Inf" spells the infinities Inf / -Inf. Data errors raise LVJSONError (a ValueError); the guide lists every error.

Command line

$ echo '{"gain":2.5,"reading":NaN,"limit":Infinity}' | lvjson to-portable
{"gain":2.5,"reading":null,"limit":null}
$ echo '{"x":0.1,"limit":-Inf}' | lvjson to-labview --number-style labview
{"x":0.10000000000000000555,"limit":-Infinity}
$ echo '[NaN, 1e400, "NaN"]' | lvjson check --strict
<stdin>: valid, non-finite values: NaN x1, numbers that overflow a double x1

Files work too (lvjson to-labview data.json -o out.json). Input is read as UTF-8 bytes and output written as UTF-8 whatever the console code page. Exit status: 0 success, 1 bad input, failed conversion, --strict finding or closed output, 2 bad usage, 130 interrupted.

Why

Python's json.loads already parses what LabVIEW 2026 writes: NaN, Infinity and -Infinity are the tokens the standard library uses too. What lvjson adds is the boundary around that parse:

  • A strict mode. The non-finite tokens are not RFC 8259 JSON, which says values such as Infinity and NaN are not permitted. to_portable and nan_inf decide what a strict consumer receives (null, the tokens, or an error) instead of failing downstream.
  • Negative zero. Flatten To JSON writes a -0.0 double as -0; json.loads returns the integer 0, and LabVIEW 2026's own Unflatten From JSON reads it back as +0.0. lvjson.loads returns -0.0, the double that was flattened.
  • LabVIEW's number form. Flatten To JSON writes 0.1 as 0.10000000000000000555 and 1.0 as 1; json.dumps writes 0.1 and 1.0. number_style="labview" reproduces every captured LabVIEW string byte for byte, including exact ties that Python's own '.20g' formatting rounds the other way.
  • Other spellings. Inf / -Inf from other producers are read and can be written on request, never touching string contents.

Evidence

Eleven files in tests/fixtures/labview2026/ come from LabVIEW 2026 (26.3.1f1) running the shipped example examples\Strings\Unflatten From JSON.vi unmodified with chosen DBL values: the strings its Flatten To JSON node wrote and the doubles its Unflatten From JSON nodes read back from them, with a manifest of method, inputs and hashes. NI's function pages and RFC 8259 were fetched on 2026-10-13 for the source tests (only their manifest is in the repository). The guide says what each capture shows and what was not verified.

License

MIT. See LICENSE.

Metadata

Release files for lvjson 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lvjson 1.0.0
File Size Uploaded Provenance Actions
lvjson-1.0.0.tar.gz 58.0 kB Without provenance Details for lvjson-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lvjson 1.0.0
File Interpreter ABI Platform Actions
lvjson-1.0.0-py3-none-any.whl Python 3 none any Details for lvjson-1.0.0-py3-none-any.whl

Total release size: 83.1 kB

Release files / lvjson-1.0.0.tar.gz

Download URL lvjson-1.0.0.tar.gz
Size 58.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e9a5572a360a228e4b736e3068d48031ea1ff4298aaaae383abb9a0fcf734ca0
BLAKE2b-256 checksum
How to use checksums
eef316c5f35aefdbb988ac4073ce388c97ea42540c473fc1cf38683e82391620
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / lvjson-1.0.0-py3-none-any.whl

Download URL lvjson-1.0.0-py3-none-any.whl
Size 25.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ff601961b77a9f4a71f2fbc33944c6c2d1c2ed85aa7244195eafb8a819266038
BLAKE2b-256 checksum
How to use checksums
e8741f83efbb2834ae69add5a988bfc3b9a0f1a72087bd81526a8a0c4fe2b0f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Security for lvjson 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page