W3C home > Mailing lists > Public > public-linked-json@w3.org > May 2013

Re: Type Coercion question

From: Rob Hoare <public-linked-json@robhoare.com>
Date: Tue, 30 Apr 2013 21:36:37 -0700
Message-Id: <1367382997.22063.140661225018381.0D50056E@webmail.messagingengine.com>
To: Markus Lanthaler <markus.lanthaler@gmx.net>, public-linked-json@w3.org
On Sun, Apr 28, 2013, at 01:41 AM, Markus Lanthaler wrote:

> Please keep in mind however that type coercion just assigns
> datatypes, it does not do any type conversions or transformations at all.

That's the bit I wasn't really understanding.  I read "coercion" as
meaning "forcing" (as that's what the word means).  In reality it seems
to be a "Type Hint" instead, which is useful, but different.

> Type coercion doesn't validate the values. It assumes
> you know what you are doing.

Or, to put it another way, it assumes you are originating the data.  Not
really useful for data from an external source until it has been
validated unfortunately.

> So you just walk over your JSON tree and whenever you find an object having
> both an @value and @type member, you would look in your datatype/service
> map and run the transformation.
> 
> It might also make sense to have a look at Antonio's JSON-LD macros:
> https://github.com/antoniogarrote/json-ld-macros
> 
> AFAICT they are not intended for the transformations that you need but
> might provide some code that you could reuse

That is actually very close to what I'm trying to do.  The way it uses
another json document to specify the "transformation" is interesting. 
After a first read of the documentation I may simply need to add another
function (or set of functions) using the @declare. The rest of what it
does is very useful as well (for renaming keys, adding namespaces, etc).
 I'll try out some ideas using it later this week.

Thanks Markus (and Antonio), you've been very helpful and its become
clearer to me what is possible.  I'll let you know if/when I have a
working example online.

Rob
Received on Wednesday, 1 May 2013 04:36:59 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:53:21 UTC