Comments (7)
If you would just like a cleaner syntax for quickly parsing snippets, you could of course create a helper proc:
proc yajl_parse {json} {
set object [yajl create #auto]
set parsed [$object parse $json]
$object delete
return $parsed
}
from yajl-tcl.
Once this happens it actually breaks the object forever as well so that all future parse calls (including those that would have succeeded before this) fail.
Update: It fails when [$j parse] is called twice on a single instance without starting over and resetting from scratch. This is a pretty bad situation when you are passing it around to various procs that need to handle things.
Here is an example of it dying if you call it twice with the generated value itself:
% set j [yajl create #auto]
yajl12
% $j map_open map_key persist number 1 map_close
% set json [$j get]
{"persist":1}
% $j parse $json
map_open map_key persist number 1 map_close
% $j parse $json
parse error: trailing garbage
{"persist":1}
(right here) ------^
So I guess the [parse] command is actually adding to the final $json object? not sure what is happening here to cause it.
calling [yajl reset] does fix it but that kills the data being built which essentially requires multiple yajl objects to reliably parse anything without worry of errors from other procs since you can only ever parse one time per object.
from yajl-tcl.
I don't think using the same object simultaneously for parsing and generation activities is really a use-case that was intended. I haven't looked deep enough to determine if it is feasible to make work as you intend yet, but at the moment I'd probably lean towards making any of the "parse" methods generate an error if it is still being used for generation without an intervening "reset".
from yajl-tcl.
I mean if that is the case, it kind of backs up the concept of making the [parse] command a static method and removing it from the object all together - otherwise it simply creates confusion and conflicts since they are 100% different at that point if they are not ever meant to be used together without breaking each other.
from yajl-tcl.
It cannot be easily static for the previously stated reasons of needing to store substantial state and callback data during the process of the parse (additionally we allow for incremental parsing of large messages over multiple statements). If you need to do two unrelated operations simultaneously, then you need to create two separate objects.
from yajl-tcl.
The above example probably needs a catch
to handle errors during the parse, in order to avoid leaking the object without deleting it.
from yajl-tcl.
I ended with the following: https://github.com/Dash-OS/tcl-modules/blob/master/json_tools-1.3.0.tm#L412-L420
try/catch is the responsibility in this case of the caller since that is a lib. Since it is using a single object in this case it ends up working well - let me knwo fi there is a problem with my logic there but it appears to work (ignore description mentioning it is a bug, that was before your replies above :-P)
from yajl-tcl.
Related Issues (18)
- "make install" fails due to missing docs HOT 4
- Something is too slow... HOT 10
- That the "parse" method defines a number callback prevents the integer and double callbacks from ever being invoked
- Update to support yajl 2.x branch HOT 1
- Configure doesn't work HOT 3
- Add map_json HOT 3
- yajl "number" should reject invalid arguments
- Atom Editor / Syntax Highlighting HOT 1
- Add [yajl parse] command HOT 4
- Add json parsing into simple key/value dict compatible format HOT 1
- Not linked with libyajl - TCL 8.5+ cannot load - Ubuntu (work-around) HOT 8
- What is the current stable version? HOT 3
- Documentation website is missing json2dict
- json2dict converts unquoted true and false to numerical boolean HOT 6
- yajl "number" type does not reject blank arguments HOT 1
- Issues while processing json containing braces HOT 6
- yajl parse returns "boolean" but the command is named "bool"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yajl-tcl.