This project is not yet functional, particularly for Node!
Descend-through JavaScript or JSON objects in a declarative manner (and optionally compatible with the Clarinet API, though potentially more granular, e.g., with distinct handlers for different scalar value types, and possessing methods available by default in a more readable CamelCase form).
Note that dj is not intended as a streaming string parser, though
walkJSONString()
is provided for descending through whole JSON
strings. Clarinet is more
likely the better choice for such cases.
-
Converting JavaScript structures to JSON
-
SAX-like parsing over XML/XHTML-as-JSON solutions like Jamilih or JsonML
-
XSL-like transformations of JSON (or XML-as-JSON), e.g., to JHTML
-
Alternative
JSON.stringify()
implementations -
Template transformations (with the option of whether to ultimately replace original content), e.g., whether with output in Jamilih or JsonML JSON (or JS objects with event handlers) or as string or DOM output (see JTLT project).
npm install dj-json
Node:
const DJ = require('dj-json');
Browser:
<script src="dj/lib/DJ.js"></script>
If you wish to utilize ObjectArrayDelegator
, Stringifier
, and/or
DJClarinet
, you will need to load the following as well:
<script src="dj/lib/DJ.ObjectArrayDelegator.js"></script>
<script src="dj/lib/DJ.Stringifier.js"></script>
<script src="dj/lib/DJ.DJClarinet.js"></script>
// Use the DJ global
Unlike musicians who use oboes or clarinets to pipe their breaths of data (piecemeal) from an ongoing streaming source (someone's lungs), D.J.'s may create new works using another complete work as the source of their data (i.e., records). They may play an entire record from start to finish or scratch and selectively sample from such a solid complete source record which is akin to what dj does in starting with complete JavaScript or JSON objects as the data source.
-
Accurate, easy to use, small, fast, memory-efficient, universal in coverage, clean code
-
Convenient (e.g., with overridable methods) but not auto-creating likely useful polyfills like
Object.keys()
,Object.getOwnPropertyNames()
,JSON
, etc. Might reconsider optionally auto-exporting them, or adding as handler arguments, in the future, but not planning for now. -
Context-aware (handlers to include parent objects as well as values or JSONPaths)
-
Customizable: Ability to override/customize any functionality and allow custom types but without need for reimplementing iteration routines
-
Offer optional support of regular JavaScript objects (including those potentially representing XML/HTML with events)
-
Allow pull or auto-push reporting
-
Configuration vis-a-vis Clarinet/sax-js options:
-
Decided for now against
trim
/normalize
options as inClarinet
as seemed not very useful, though could be allowed easily instringHandler
-
lowercase
andxmlns
seem too XML-specific -
position
has analogue in JSONPath goal
-
-
Decided against causing conversion to string and feeding into
Clarinet
(orJSON.parse(obj, reviver);
) as use cases of beginning with JSON rather than merely converting to it were too great (toward JS as main environment or even content-type). -
Decided against
Clarinet
handler names as considered ugly relative to CamelCase (despite JS-event-style-familiarity) though providing aClarinet
adapter -
Decided against passing
Object.keys
(or other exports of Object properties likegetOwnPropertyNames
) tobeginObjectHandler
/beginArrayHandler
(and corresponding end methods) as auto-iteration of keys/values ought to address most use cases for obtaining all keys and user can do it themselves if needed. We did pass length of array to begin andendArrayHandler
, however. -
Have module support standard export formats
-
Demonstrate functionality by implementing
JSON.stringify
though provide empty version
-
Complete existing code!
-
Restore tests with mocha (had been using nodeunit)
-
Ensure works with Node
-
-
Create JSON serialization; utilize JSON Namespaces (like these)?
-
Provide demo which overrides add() to do its own non-string concatenation work
-
Pull as well as automatic cycling
-
Adapt (as with SAX) to allow DOM
TreeWalker
-style traversal along with XSL-style iteration (optional as to whether to replace the original content; see JTLT) -
JSONPath
-
Allow
JSONPath
on supplied data object -
Reimplement as
JSONPath
dependency (calling it by default with$
and$..*
)?- Provide JSONPaths to methods?
-
-
TreeWalker/NodeIterator equivalents?
-
Add array-extra methods along with functional join?
-
Infinity
,NaN
,String
,Number
,Date
, etc. -
Add depth level property (which could be used, e.g., by a
JSON.stringify
implementation)-
Implement self-sufficient
JSON.stringify
-
Finish array/object (call
delegateHandlersByType
insidekeyValueHandler
or in object/arrayHandler?; change keyValueHandlers to return commas, etc.) -
Avoid functions/
undefined
/prototype
completely, and converting nonfinite tonull
-
Support replacer and space arguments in our stringifier and remove
JSON.stringify
dependency for strings
-
-
-
Add
valueHandler
option for generically handling values (as in Clarinet) -
Allow asynchronous value-adding (e.g., to parse with
setTimeout
to avoid performance problems) -
Integrate with allowing stream input as in Clarinet?
-
Add getXPath() for DOM node prototype (modify this and avoid 2nd argument via
ownerDocument
) -
Report current XPaths to
SAX
and followSAX
API for objects (slightly more linear than climbing through children manually) (then utilize in from-DOM conversion likeJHTML
/Jamilih
)? -
Iterating DOM: https://github.com/brettz9/jWalker