Skip to content

std.parseJson #479

Closed
Closed
@jwise

Description

@jwise

I have recently found myself with cause to parse some ill-formed partial JSON -- a library that we are incrementally converting to Jsonnet was originally parsed by the C preprocessor, and had files like this:

main.jh:

{
  "unit_1": {
#include "unit_1.jh"
  },
  "unit_2": {
#include "unit_2.jh
  },
  ...
}

unit_1.jh:

  "out": {
    ... data ...
  }

I'd like to be able to load a unit_1.jh directly into Jsonnet without invoking an external pass. Obviously, I can't hand it to import, since it's ill-formed. importstr can load it so that I can do extra work on it, but once I have a string, I can't convert it to an object. Really, I'd like to be able to do something like:

eval ("{" + importstr "unit_1.jh" + "}")

Or, even better,

local importjh(f) = eval("{" + importstr f + "}")

though that would require changes along the lines of #196, too.

This is closely related to #460, but maybe more general. One key difference is that #460 wants to be "safe"; in this case, "everybody knows" that any time you type "eval", you deserve whatever happens next 😄 We intend to use this only on trusted JSON databases.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions