public function testJsonOut() { $j = new haxe_ds_StringMap(); $j->set("a", 1); $j->set("b", 2); $txt = haxe_format_JsonPrinter::hprint($j, null, null); $this->assertTrue($txt === "{\"a\":1,\"b\":2}" || $txt === "{\"b\":2,\"a\":1}", _hx_anonymous(array("fileName" => "JsonTest.hx", "lineNumber" => 12, "className" => "harness.JsonTest", "methodName" => "testJsonOut"))); }
static function phpJsonEncode($val, $replacer = null, $space = null) { if (null !== $replacer || null !== $space) { return haxe_format_JsonPrinter::hprint($val, $replacer, $space); } $json = json_encode(haxe_Json::convertBeforeEncode($val)); if ($json === false) { throw new HException("invalid json"); } else { return $json; } }
public function renderRow($r) { $row = new haxe_ds_StringMap(); $_g1 = 0; $_g = $this->tab->get_width(); while ($_g1 < $_g) { $c = $_g1++; $key = $this->view->toString($this->tab->getCell($c, $this->header_row)); if ($c === 0 && $this->header_row === 1) { $key = "@:@"; } $value = $this->tab->getCell($c, $r); $row->set($key, $value); unset($value); unset($key, $c); } return haxe_format_JsonPrinter::hprint($row, null, null); }
public function encodeTable($name, $t, $render = null) { if ($this->output_format !== "copy") { $this->setFormat($this->output_format); } $txt = ""; $this->checkFormat($name); if ($this->format_preference === "sqlite" && !$this->extern_preference) { $this->format_preference = "csv"; } if ($render === null) { if ($this->format_preference === "csv") { $csv = new coopy_Csv($this->delim_preference); $txt = $csv->renderTable($t); } else { if ($this->format_preference === "ndjson") { $txt = _hx_deref(new coopy_Ndjson($t))->render(); } else { if ($this->format_preference === "html" || $this->format_preference === "www") { $this->renderTable($name, $t); } else { if ($this->format_preference === "sqlite") { $this->io->writeStderr("! Cannot yet output to sqlite, aborting\n"); return ""; } else { $value = coopy_Coopy::jsonify($t); $txt = haxe_format_JsonPrinter::hprint($value, null, " "); } } } } } else { $txt = $render->render($t); } return $txt; }
static function hprint($o, $replacer = null, $space = null) { $printer = new haxe_format_JsonPrinter($replacer, $space); $printer->write("", $o); return $printer->buf->b; }